Featherweb Blog

Blog index

dan-christian padure

B.U.T.S. again,

one aha moment later..

I'm one step closer to the final solution. It suddenly became clear to me that this theme switching could be further simplified, ending up with even less code and less weight. One of the advantages of doing your writing directly in the html document, is that you have the head of the document always available. My current proposal is to just change the current color-name in the head to the desired color name.

The basic idea is to have two stylesheets: the general one, containing everything, except colors ("blogstyle-min.css" in the image) and a very small second stylesheet, containing only the color theme ("light.css" in the image). All that is needed is to replace the word "light" with the name of one of the other colors. The color.css's are so small, just two lines, I manually wrote them minified. 😉

Its fun to play with this. Not only is it very easy, it is also reliable and adhering to the principle:

The fastest code is the one that does not exist ~ Sylvain Kerkour

Just like in my former post the color circles are not a theme switcher. They are links to 10 different html pages, only here to demonstrate how the different color themes look like.
The method I explained above however, changing the color name in the head of the page, is a real theme switcher. It enables one document to have 10 different color themes, almost effortlessly. Another advantage of this way of switching themes is that it automatically "remembers" a writer's preferred theme. No coding needed.

But I should stay open-minded. Not everyone will like this approach. Many people will be hesitant to touch the source. Moreover I can imagine writers who don't really care about the color theme, concentrated as they are on writing the content. In that scenario those writers would probaly love to offer a theme switcher to their audience. I had hoped the theme switcher by George Martsoukos would be the answer, but I soon discovered its shortcomings and/or mine dealing with it. At the moment I'm just looking around, hoping for small size. It will almost certainly have some Javascript. To be continued...