Forum Moderators: not2easy
html is your outermost element, talking about it in terms of a sibling can't be done equally in many browsers, on top of that, siblings themselves are already not supported by e.g. IE6
For example, our Yahoo store default css used:
*:first-child+html #bodyshell { width:610px; }
But this seems to have the same effect and works also:
#bodycontent #messagearea {
border: 1px solid #FF00FF;
width: 90%;
margin: 0 auto;
font-family: Calibri, Arial, Helvetica, sans-serif;
font-size: 1.2em;
}
Since #messagearea is a descendant of #bodycontent.
I can only test this in IE7 and FF - am I missing something?
The clearfix method to auto clear floats uses the pseudo class ":after".
eg:
#navbar:after, #footer:after {
content: ".";
display: block;
height: 0;
margin:0;
padding:0;
clear: both;
visibility: hidden;
}
IE doesn't recognize the pseudo-element ":after", AND has a "HasLayout" issue with floated elements (the contents can exceed the dimensions of the floated container if no height or height:auto is designated).
So the IE6 hack was simply to give IE6 a "minimum" height of 1% (since the content would always be over 1% it forced IE to conform to the floated element's dimensions).
The hack to clear the float was:
* html #navbar, * html #navbar {height:1%}
Simple.
BUT! IE7 fixed the bug that allowed the old "star" hack, yet didn't fix the "HasLayout" float issues.
The brilliant solution to force IE7 to give the element a minimum height was the first-child pseudo element (which IE recognized) along with "min-height" (which it also now recognized) ... so to get IE7 to use a clearfix type auto-clear the hack is:
*:firstchild + html #navbar {min-height: 1px;}
Most pros use the cleafix method like so:
#navbar:after, #footer:after {
content: ".";
display: block;
height: 0;
margin:0;
padding:0;
clear: both;
visibility: hidden;
}
/* fix for IE6 */
* html #navbar, * html #navbar {height:1%}
/* fix for IE7 */
*:firstchild + html #navbar {min-height: 1px;}
*:first-child+html #nav ul li
{ padding-bottom: 5px; }
This :first-child pseudo-class matches the first child element of its parent element.
In the above example, first-child ONLY matches the first list item in #nav ul and gives it a 5px bottom padding. It doesn’t match anything else.
I still can't quite figure out what that hack does, or when (and when not) to use it.
For example:
*:first-child + html #bodyshell {
width: 86%;
border-left: solid 150px #FFF;
}
#bodyshell {
width: 86%;
border-left: solid 150px #AAA;
}
In that, IE7 shows up with a white border, Firefox with a grey border, so it is applying one color to IE7 and another to FF.
In other words, FF is picking up the ID without the "first child", but IE7 is not.
[edited by: Wlauzon at 6:20 pm (utc) on May 16, 2008]
In order to get IE7 to change the border color, it has to be the *:first-child+html version. IE7 will not recognize just the #bodyshell.
Firefox is just the opposite, it has to be #bodyshell, the *:first-child+html #bodyshell does not work.
So in order to get the border color to show up in both IE7 and FF, I need 2 separate lines.
[pre]#bodyshell {
width: 86%;
border-left: solid 150px red;
}[/pre]
And if you want different result: then too drop the hack and use conditional comments instead.
[pre]
<link rel="stylesheet" type="text/css" href="/style.css" />
<!--[if IE 6]>
<link rel="stylesheet" type="text/css" href="/ie6.css" />
<![endif]-->
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="/ie7.css" />
<![endif]-->[/pre]
As for specificity:
Remember: The world is a better place without hacks!
This is what I have in there now:
#bodyshell {
width: 86%;
border-left: solid 150px #400;
}
*:first-child + html #bodyshell {
width: 86%;
border-left: solid 150px #040;
}
If I use *only* one or the other, only one picks it up. (I have them set to different colors now so I can see what is going on).
What is odd is that if I use ONLY the #bodyshell, both pick up the border color, but IE7 does NOT pick up the width. I have to use both since Firefox will ignore the *:first-child statement.
This may be a width bug or selector bug in IE7, not sure what is going on. I thought it might be a "haslayout" bug, but none of the usual "fixes" work (like zoom: 1;)
Nowever, if I add "min-width: 86%;" to the #bodyshell statement it seems to work OK for both.
Not sure what it is doing in IE6, since my old computer died...
[edited by: Wlauzon at 5:02 am (utc) on May 18, 2008]