I'm working on a CSS preprocessor, which means that I have the god power to decide what the output HTML will be. I wasn't able to find an information about how the browser apply styles to the elements in lower level. Which one is better?
Let's say that I have width: 100% and I have to apply this to several elements.
body { width: 100%; }
header { width: 100%; }
footer { width: 100%; }
This could be written like that as well:
body, header, footer { width: 100%; }
Which makes the size of the CSS lower. However, this also means that if I want to apply another style to the footer for example I'll end up with something like this:
body, header, footer { width: 100%; }
footer { font-size: 23px; }
And here is the question - the footer element is written twice in the CSS and is that mean that the browser will parse this slower then:
body, header { width: 100%; }
footer { width: 100%; font-size: 23px; }
I believe that combining of selectors is a good thing. However, when the preprocessor starts implementing this it will output styles like that:
.login-box { margin-top: 10px; }
.login-box { font-weight: bold; }
And that's because it thinks that there will be another element matching margin-top: 10px for example. So, is this a problem. I mean if I have a lot
.login-box { margin-top: 10px; }
.login-box { font-weight: bold; }
And not everything in one place:
.login-box { margin-top: 10px; font-weight: bold; }
P.S. the question is not about the specificity
==================== EDIT 01 ====================
Here is some SASS code:
%full-width {
width: 100%;
}
%margin-reset {
margin: 0;
}
body {
@extend %full-width;
@extend %margin-reset;
}
And the output is
body {
width: 100%;
}
body {
margin: 0;
}
So, the question is: is that actually correct. Isn't it better if the preprocessor outputs:
body {
width: 100%;
margin: 0;
}