We recently implemented something that we called "CSS compilation", something like what methodin answered. Our compilation (done using the PHP backend) creates one compiled css file for each module, and thus one CSS file is loaded at runtime. This gives us the freedom to define as many CSS files as possible without worrying about performance. To do this, we defined an array $moduleCssrelation containing the ratio of module-CSS files in the configuration file of our project (module, for example, login, home, etc. And CSS files to load for each module). Describing more details about this at the end, because it is the core of style architecture.
This is the basic CSS plan we used: -
- Studied in detail all the modules marked with style styles / reusable components, and saw that
- header section, footer and left menu are required in each module
- there are many modules that have a tabular section displaying some lists in the center (leaving a common title, footer and left menu), and there are many modules that display some elements, such as a user details page, a class details page.
We had all the styles in one file delivered to us by the design team. Then we decomposed one CSS file into several fragments in accordance with the style templates, as described in the previous step. So, we created some files, for example -
common.css Contain the style of the header, footer, left menu
listings.css Contains all style definitions for components displayed only on listing pages.details.css As with the preface, if you have a .detailsRedHeading class that is only needed for detail pages, define it here.
Any additional styles - suppose that many modules require a pop-up window with their own style, and then put these styles inside popups.css instead of defining these styles in common.css or any other file. Remember the freedom we need to define as many css files as possible.
To simplify subsequent theme changes
I never applied your idea "I tried to put all the layout (position, size, etc.) in 1 file, while all the decorations (color, background, etc.) in another", but if that helps you, you can add that to this architecture. Break common.css in common_layout.css , common_design.css and similarly for others.
Also, make sure that you use the maximum possible reuse of the style for the first time. Avoid style declarations as follows: -
.listingsBody { font-family:Trebuchet MS,Liberation Sans,DejaVu Sans,sans-serif; font-size: 12px; .. some listing page styles .. } .detailsBody { font-family:Trebuchet MS,Liberation Sans,DejaVu Sans,sans-serif; font-size: 12px; .. some details page styles .. }
Instead, do the following: -
.siteMediumFont { font-family:Trebuchet MS,Liberation Sans,DejaVu Sans,sans-serif; font-size: 12px; } .detailsBody { .. some details page styles .. } .listingsBody { .. some listing page styles .. }
I have seen many designers do this. This habit in more complex cases can make things really difficult later on.
Compilation Details: -
After we finish applying CSS changes, we will run the compilation code that does the following: -
$moduleCssrelation = array("class_details"=> array("details","popups"));
Go $moduleCssrelation and create a compiled file from the contents of the css file names for each module. for example, if the class_details module needs the details.css , popups.css , then it creates the common-details-popups.css , which will also be loaded for class_details , as well as any other module that needs these two css files.