Forum Moderators: not2easy
From this
#div.mybox {
margin-top:4px;
margin-bottom:4px;
margin-left:2px;
margin-right:2px;
padding-top:4px;
padding-bottom:4px;
padding-left:2px;
padding-right:2px;
font-weight:bold;
font-style:italic;
font-size:12px;
font-family: Times, serif;
background-color: #FFFFFF;
background-image: url(myimage.png);
background-repeat: no-repeat;
background-position: 0% 0%;
}
to this
#div.mybox {
margin:4px 2px 4px 2px;
padding:4px 2px 4px 2px; ;
font: italic bold 12px Times, serif;
background: #FFFFFF url(myimage.png) no-repeat 0% 0%;
}
#div.mybox {
margin:4px 2px 4px 2px;
padding:4px 2px 4px 2px; ;
font: italic bold 12px Times, serif;
background: #FFFFFF url(myimage.png) no-repeat 0% 0%;
} to this
#div.mybox {
margin:4px 2px;
padding:4px 2px;
font:italic bold 12px Times,serif;
background:#FFF url(myimage.png) no-repeat 0 0;
} managed to shave off a few more bytes
esp if myimage.png hasn't been optimised
It might be smaller as a progressive jpeg or an interlaced gif
And... it will be (what's the antonym for optimal?) a waste of time (and money) if your code is ever going to be maintained by someone who doesn't know about or dislikes declaring margin, padding, border, etc attributes in one line, clockwise from top
#div.mybox,#div.hisbox,#div.herbox{
margin:4px 2px 4px 2px;
padding:4px 2px 4px 2px;
background:#FFFFFF url(myimage.png) no-repeat 0% 0%;
}
#div.mybox{
font:italic bold 12px Times,serif;
}
#div.hisbox(
font:10px Verdana,sans-serif;
}
#div.herbox{
font:10px Arial,sans-serif;
}
You also save bytes if:
a) get rid of unneccesary spaces after ',' or ':',
b) remove comments,
c) put the styles on one line,
d) or better still put everything on one line.
You can get editors which do all this for you. The best way I find is to keep an intelligble original, and then produce an optimised copy for use on the site.
Please define WHO/WHAT/WHY we would need to optimize CSS files - in your opinion.
For me it's for the people on dial-up, lots of people still using it here in the states. Trimming a few KB's off a CSS file by itself doesn't amount to much but if you do it for everything, especially images then you can trim more than few KB's.
As another poster mentioned it's also a lot easier to read, at least IMO.
There are exceptions to that of course, the CSS file for the new phpbb3 is a whopping 72K approx. Not sure of the exact figure because I started customizing before I looked. I already chopped off 22K simply by getting rid of redundancy.