Hi brettxy, I'm not sure I understand the question exactly, but if you are asking how browsers choose between the
styles in different stylesheets, the answer is they mostly don't - they are supposed to choose between
whole stylesheets then apply the contents (styles) of whichever stylesheet has precedence. However the cascade still applies, plus browsers/versions have known errors which means they don't always get the priority correct.
Duplication could occur when changing the design for different media, say specify different font-size, colours, remove background/presentational images etc for printing, and enable that sheet by including the
"media" descriptor [w3.org] in the link element:
<link rel="stylesheet" type="text/css" href="print.css"
media="print">
There is often duplication when providing an alternate stylsheet that allows the user to change the default styling by using a "stylesheet switcher" or view>>>style. For example, extra large font with high contrast colours for easier reading by setting the
rel attribute [w3.org] to alternate:
<link
rel="alternate stylesheet" type="text/css" href="alternate.css" >
The other two
types of stylesheets [w3.org] are persistent, which has no title, is enabled by default and always applied, and any number can be applied to the same document, and preferred which has a title, enabled by default, but only one can be applied per document:
<link rel="stylesheet" type="text/css" href="persistent.css">
<link rel="stylesheet" type="text/css" href="preferred.css"
title="preferred">
So, in summary, if you
did have multiple stylesheets with the same classes, but different declarations, the browser should decide on the basis of:
media (will only be applied to the correct media )
rel (alternate will onyx be applied if selected by the user),
title = no title = persistent will always be enabled
title= title = preferred will always be enabled
Good code management avoids "duplication", but on larger sites or with teams of coders, code is sometimes split into different sheets. For a small site probably just unnecessarily increases server hits. But using your example, put .content and .footer in css1.css, .container etc in css2.css. Make both persistent (or one persistent and one preferred) and the browser will apply the styles from each.
However, what if poorly maintained code creates duplications? For example, these sheets and styles:
<link rel="stylesheet" type="text/css" href="persistent.css"> h1 {color:red} h2 {color:blue}
<link rel="stylesheet" type="text/css" href="preferred.css" title="preferred"> h1 {color:green} h3 {color:tan}
<link rel="alternate stylesheet" type="text/css" href="alternate.css" > h1 {color:lime} h3 {color:silver}
<link rel="stylesheet" type="text/css" href="print.css" media="print" > h1, h2, h3 {color:black)
You should get:
h1 = green (preferred takes priority and last in cascade)
h2 = blue (no duplication, from the persistent, applied by default)
h3 = tan (preferred takes priority and last in cascade)
If the user selected an alternative sheet it should over-ride:
h1 = lime (alternate takes priority )
h2 = blue (no duplication from the persistent, applied by default)
h3 = silver (alternate takes priority )
If the user prints, the print sheet should over-ride so all the headers would be black.
However, some browsers muck up the relationship between preferred and persistent, and reversing the order means you can end up with:
<link rel="stylesheet" type="text/css" href="preferred.css" title="preferred"> h1 {color:green} h3 {color:tan}
<link rel="stylesheet" type="text/css" href="persistent.css"> h1 {color:red} h2 {color:blue}
h1 = red
h2 = blue
h3 = tan
Finally, if you accidentally include titles and create two preferred sheets, the first should take precedence, but some browsers wrongly apply the last:
<link rel="stylesheet" type="text/css" href="persistent.css" title="persistent"> h1 {color:red} h2 {color:blue}
<link rel="stylesheet" type="text/css" href="preferred.css" title="preferred"> h1 {color:green} h3 {color:tan}
h1 = red (but sometimes wrongly green)
h2 = blue (from persistent, no duplication)
h3 = blue (but sometimes wrongly tan)