Since I've given you a lot of examples using HTML, it's only right that I should show you a reasonably complex and large Stylesheet that actually styles a website. As it so happens, I have one: the Stylesheet that formats this book. This may seem put together higgledy-piggledy, and in many cases it was. There's a reason for that, and that reason lies in the three ways a Stylesheet can be created for a website:
I wish you all the luck in the world should you go with method #1. Likely, you'll find yourself adding rules while the rules you created at first languish and gather dust.
Most Stylesheets are created with a combination of 2 and 3: A few webpages are created, styled, and the rest of the website is created, with new rules added as they are needed. A FEW rules may be laid down through method 1, but those are usually very general rules (centering all headers, the basic font you want, and the like).
This has a lot of what I talked about in the chapters on CSS. I even import another style sheet into this one, specifically, chapter_numbers.css
, which is used not only in this Stylesheet, but also in four other stylesheets. It is integral to all of them, so I simply use an @import rule instead of a separate link
element.
You'll also notice that I have an outline. While it's not necessary, it did help me figure out what rules are where, as they are organized by context to make this Stylesheet easier to follow and edit.
So, without further ado, book_main.css
@import url('./chapter_numbers.css');
/* ----------------- Sheet Outline -----------------