Stylesheets
Welcome to the official CMS Made Simple documentation pages. We make a continuous effort to keep the information here up to date! However, dear user, we highly value your assistance in the process.
We need your assistance to make the documentation accurate, user friendly and understandable. Therefore we welcome any tips or suggestions regarding documentation. Thank you in advance for your contribution.
However, we will not respond to technical support questions submitted using this form. If you are having difficulty with CMSMS and cannot find the solution on this website, please submit your question appropriately on our support forum at: http://forum.cmsmadesimple.org. Please remember to follow the forum rules when posting.
Cascading Style Sheets (CSS) are used to add layout and formatting to your templates.
Basic CSS Usage
For the majority of basic web sites, it is just a simple matter of creating your stylesheet, then linking it to your template(s). This is accomplished by performing the following steps:
- Go to Layout/Stylesheets and click the Add a Stylesheet button near the bottom
- Give the stylesheet a unique Name, and enter your css data in the Content box.
- Click Submit
- In the Stylesheet list, click on the icon to Attach Stylesheet to Template
- Choose the Template in the dropdown, then click Attach to this Template
To remove an association, choose the Attach Stylesheet to Template option in the Stylesheet list, and click Delete next to the association.
Tips
- Because Stylesheets are cached, absolute URLs are necessary. For example, use:
(see Smarty section below for more details)
- background: url([[root_url]]/uploads/images/background.png) repeat-y;
- There is a limit of 64k per stylesheet. If you need more, use multiple stylesheets.
- Use the cms_stylesheet tag in your Template. You only need this tag once, Stylesheets are combined into one call.
Advanced CSS Usage
CMSMS offers a lot of advanced features for Stylesheets, and with the ability to include Smarty tags, the possibilities are endless.
Multiple Stylesheets
Stylesheets are stored in the database, combined, and cached. This allows you to maintain separate stylesheets for layout, formatting, accessibility, etc., but only have one call to speed load times.
The order of Stylesheets is maintained, and can easily be reordered by clicking the up and down arrows in the Current Associations list.
Using Media Queries
Since CMSMS 1.11, when editing a Stylesheet in the backend, a "Media Query" tab has been introduced.
Within the "Media Query" textarea field any valid Media Query value as recommended by W3C can be entered.
After a value has been entered in "Media Query" textarea, "Media Type" checkbox options will be disabled.
- screen and (min-width: 300px) and (max-width: 1024px)
Output of HTML Stylesheet tag would then produce following:
- <link rel="stylesheet" type="text/css" href="path/to/stylesheet.css" media="screen and (min-width: 300px) and (max-width: 1024px)" />
You are not only limited to using this newly introduced "Media Query" field but you can as well use @media rule inside your Stylesheet.
For detailed instructions look at W3C Media Queries Syntax.
Since CMSMS 1.11 a new theme called "Simplex" has been introduced where you can find above mentioned examples of Media Queries usage.
Tag paremeters
The cms_stylesheet tag allows for various parameters for special cases.
Smarty Processing
When generating css files this system passes the stylesheets retrieved from the database through Smarty. The Smarty delimiters have been changed from the CMSMS standard { and } to [[ and ]] respectively to ease transition in stylesheets. This allows creating Smarty variables i.e.:
- [[assign var='red' value='#900']]
at the top of the stylesheet, and then using these variables later in the stylesheet, i.e:
- h3 .error {
- color: [[$red]];
- }
Because the cached files are generated in the tmp/cache directory of the CMSMS installation, the CSS relative working directory is not the root of the website. Therefore any images, or other tags that require a url should use the [[root_url]] tag to force it to be an absolute url. i.e:
- h3 .error {
- background: url([[root_url]]/uploads/images/error_background.gif);
- }
Below you will find some examples for using Smarty in your stylesheets.
Global Settings and Color Scheme
Attach all stylesheets to the same HTML template, but the "Global Settings and Color Scheme" stylesheet should be first in line.
Stylesheet: Global Settings and Color Scheme
- [[* +++++ SETTINGS +++++ *]]
- [[capture assign='path']][[root_url]]/uploads/template[[/capture]]
- [[* +++++ COLOR SCHEME +++++ *]]
- [[assign var='color_text' value='#333333']]
- [[assign var='color_a' value='#ff0000']]
- [[assign var='color_a_hover' value='black']]
- [[assign var='color_h2' value='#ff0000']]
- [[assign var='color_h3' value='#f00']]
- [[assign var='color_h4' value='#f00']]
- [[assign var='color_h5' value='#333333']]
- [[assign var='color_h6' value='#333333']]
- [[assign var='color_footer' value='#ffffff']]
Stylesheet: Layout
- a, a:link, a:active, a:visited {
- color: [[$color_a]];
- }
- a:hover {
- color: [[$color_a_hover]];
- }
- body {
- color: [[$color_text]];
- background: #fff url([[$path]]/bg_body.jpg) repeat-x;
- }
- #main h2 {
- color: [[$color_h2]];
- }
- #main h3 {
- color: [[$color_h3]];
- border-bottom: [[$color_h3]] solid 1px;
- }
- #footer p {
- color: [[$color_footer]];
- }
- #footer p a {
- color: [[$color_footer]];
- }
Stylesheet: Some module
- .some_module .some_class {
- color: [[$color_text]];
- }
Stylesheet: foreach example
Another example, to save yourself the hassle of writing vendor prefixes all the time.
- [[assign var='vendor_prefixes' value='-moz-,-webkit-,-o-,-ms-']]
- [[assign var='vendors' value=','|explode:$vendor_prefixes]]
- .some-class {
- [[foreach from=$vendors item='one']]
- [[$one]]box-shadow: 1px 1px 3px #000;
- [[/foreach]]
- box-shadow: 1px 1px 3px #000;
- }
Previous page: Export your templateNext page: Global Content Blocks (GCBs)




