So far, my experience in web design has been with very small scale sites and blogs (where there isn’t much diversity in page styling). However, I am now beginning to tackle some significantly larger scale web sites and I want to start off on the right foot by creating a scalable and maintainable css file / structure.
Currently, my method for applying styles to web pages is to give every web page a distinct ID in the body, and then when I’m designing a page my css rule will look like this:
body#news section .top { rules }
Surely there is a more maintainable approach to applying CSS for a large-scale web site?
Avoid giving each page a
bodytag with a unique ID. Why? Because if a page needs to be styled uniquely, it should have its own stylesheet.I will often have a
main.cssstylesheet, stylesheets for various similar portions of my website (like anadministration.cssfor an admin section, assuming the pages in the admin section shared a similar look and feel), and then give certain unique pages their own stylesheets (likesignup.css).I then include the stylesheets in order from least-to-most specific, because if two otherwise-identical rules are encountered, the rule in the most “recently” included stylesheet will be used.
For example, if my
main.csshad:… and for some reason, I wanted my signup page to have blue links:
The second rule will overwrite the first if my
signup.csswere included aftermain.css.