View on GitHub View on Contao

ZAD Style Switcher

An extension for Contao CMS

Creating styles

Consider the following scenario:

Then, you have to make seven stylesheets with different font size settings.

You could make seven copy of "main" stylesheet and alter only the font size settings. In this way you would get seven alternative styles, each one containing all that is needed for the site, thus making useless the "main" stylesheet. Using this strategy only makes sense if you want to perform a quick job and you have a very simple site, with a few styles. Otherwise you have to expect troubles: if you later want to change the color of a background, you will not have to change a single stylesheet, but seven ones!

The best solution is to take advantage of the opportunity to redefine styles: the "main" stylesheet will be executed first, while the style choosen by the user will be loaded later on, overriding only the font size settings and inheriting all the rest.

In our scenario, you can improve even more this technique: first of all you make sure that all font size settings in the "main" stylesheet are specified using relative units (%, em, ex). Then, you create a new stylesheet, named "font_100", with an initial value for the font size as follows:

body {
  font-size: 100%;
}

Now you can continue creating the remaining stylesheets: