Improve page-specific CSS for different color schemes For a website with four pages (blog, portfolio, profil and impressum) I have four different color schemes (for links, headings, code, etc.).  This results in bloated CSS which I want to reduce.

Here is a demo. You see the navigation items use the color scheme of the page it links to. In the demo we're on the blog page with a green theme. Styling the different pages works by adding a class to the root element (i.e. &lt;html class=page--blog&gt;).

How can I improve this approach of styling things page-dependant?

Also what kind of naming would be appropriate? I could use the titles of the pages (page--blog, link--blog, &hellip;) or the colors (page--green, link--green, &hellip;). Other ideas/suggestions?

HTML:

&lt;html class="page page--blog"&gt;
    &lt;nav class=site-nav&gt;
        &lt;a href=# class=link--green&gt;Blog&lt;/a&gt;&lt;!--
     --&gt;&lt;a href=# class=link--orange&gt;Portfolio&lt;/a&gt;&lt;!--
     --&gt;&lt;a href=# class=link--blue&gt;Profil&lt;/a&gt;&lt;!--
     --&gt;&lt;a href=# class=link--red&gt;Impressum&lt;/a&gt;
    &lt;/nav&gt;
    &lt;main class=page-content&gt;
        &lt;p&gt;Regular paragraph, containing &lt;a href=#&gt;a link&lt;/a&gt;. Crazy, huh?&lt;/p&gt;
    &lt;/main&gt;
&lt;/html&gt;


CSS:

.site-nav {
    background-color: #444;

    a {
        color: white;
        display: inline-block;
        padding: 20px;
    }
}

.link--green {
    background-color: forestgreen;

    .page:not(.page--blog) &amp;:hover {
        background-color: yellowgreen;
    }
}

.link--blue { /* ... */ }
.link--orange { /* ... */ }
.link--red { /* ... */ }

.page-content {
    a,
    h1, h2, h3, h4, h5, h6 {
        .page--blog &amp; {
            color: forestgreen;
        }

        .page--profil &amp; { /* ... */ }
        .page--portfolio &amp; { /* ... */ }
        .page--impressum &amp; { /* ... */ }
    }
}


possible solutions/ideas:


additional CSS file only used on these sites (extra HTTP request)
page-specific CSS in style tags inside the actual html document (hard to manage)
Using SASS mixins to generate the CSS for the four pages (won't reduce bloat)
Some days passed and I feel like I should share the changes I have made so far.

Naming

I started using page names instead of color names on classes and variables. This leaves me with the benefit of being able to change the color scheme of an entire page only by changing the value of the color variable.

.page--home       -&gt; .page--blog
.nav__item--green -&gt; .nav__item--blog
$green-color      -&gt; $blog-color


Generating page-specific CSS with a mixin


I need to style certain elements depending on the class I assign to the root element (e.g. &lt;html class=page--blog&gt;)
The needed arguments I pass to the mixin are $element (a selector like .site-nav or h1) and $property (a CSS property like color)
There also is an optional argument which allows me to switch to light color variations


Mixin:

@mixin themify($element, $property, $light-colors: false) {
    $pages: null;
    @if $light-colors == true {
        $pages: blog      $green-color-light,
                portfolio $orange-color-light,
                profil    $blue-color-light,
                impressum $red-color-light;
    } @else {
        $pages: blog      $green-color,
                portfolio $orange-color,
                profil    $blue-color,
                impressum $red-color;
    }

    @each $page in $pages {
        .page--#{nth($page, 1)} #{$element} {
            #{$property}: nth($page, 2);
        }
    }
}

/* Call the mixin without optional argument */
@include themify(site-nav, background-color);

/* ...use the light colors instead of the normal ones */
@include themify(site-nav, background-color, $light-color: true);


Problems with the mixin:


I can't pass a list of selectors like a, h1, h2, h3, h4, h5, h6 &ndash; Didn't find a solution so far (probably going to involve multi-dimensional lists)
Still creates the bloated CSS, but eases my work


I still would love to hear some suggestions/improvements.