Forum Moderators: not2easy
<div class="container blue">example</div>
However, I was told there's another way of combining classes. It seems to work, but I'm worried there could be negative effects, even though I don't see any (haven't tested in all browsers). Here's an example.
Instead of doing this..
.header { float: left; width: 500px; background-color: pink; color: #000; }
.content { float: left; width: 300px; background-color: red; color: #000; }
.footer { float: left; width: 400px; background-color: purple; color: #000; }
..you do this:
.header { width: 500px; background-color: pink; }
.content { width: 300px; background-color: red; }
.footer { width: 400px; background-color: purple; }
.header, .content, .footer { float: left; color: #000; }
In this example, you don't save a lot of bytes, but I assume you get the point.
I was initially worried the latest definition of a class would cause the previous to be ignored, but this doesn't seem to be the case.
sort of like this:
.header, .content, .footer {float: left; color: purple;}
.header {width: 500px; background-color: pink;}
.content {width: 300px; background-color: red;}
.footer {width: 400px; background-color: purple;}
I tested this optimization method on one of my running sites and I managed to cut off 1KB off of a 3kb stylesheet - 30%!
*{margin:0;padding:0}
means that every single element will have margins and paddings set to 0.
and
*.blue{color:blue}
means that every single element with a class="blue" -- no matter what kind of element it is -- will be the color blue.
and if you have a big CSS sheet, it is surprising how many bytes you can save just by removing whitespace and the extra colons at the end. using yours as an example, instead of
.header { float: left; width: 500px; background-color: pink; color: #000; }
you could just write
.header{float:left;width:500px;background:pink;color:#000}