IE7 prob with li display:inline-block;

in reset:

li {
        [FONT="Courier New"]display:inline-block; [/FONT]
}

in my code for one of the pages:

[FONT="Courier New"]body.galleries ul#photos li {
		height:255px; 
		margin:0 10px 30px 0;
		position:relative; [/FONT]
	}

now this looks well and good in all browsers I have on my mac (FF 3, Safari, Chrome), and in IE8; but today I looked at it in IE 7 for the first time and the galleries links were stacked instead of side-by-side… I guess in IE7 (& most probably IE6 too) for some reason the display:inline-block in reset is not taking for body.galleries ul#photos li…

would body ul li in reset work? ( can’t test in IE7 now)

thank you…

Legacy IE (7 and lower) can’t make block-level tags be inline-level. PERIOD.
It’s why you’ll often see the hack


li {
  display:inline-block;
  display:inline !ie;
}

It’s ugly, but it works – remember, IE7 and lower display:inline behave like inline-block anyways.

Generally though, this is why when/if I can get away with it I don’t even THINK about trying to style LI, set them to display:inline for all browsers then pretend they don’t exist.

yes but my question is why in IE7 this line in reset is ignored…

li {
display:inline-block;
}

so are you saying that for IE7 (& older) you can ONLY use display:inline and that display:inline-block is ignored?
so then *display:inline; should work for for IE7 & IE6 yes?

and what is " !ie; " ??? I’ve never seen this… I searched for it, didn’t find any ref. to it at all…

thank you…

Because LI is a block-level element, IE7 and lower CANNOT set inline-block on it. Inline-Block on IE7 and lower ONLY works on inline-level elements. (span, anchor, i, em, etc).

Correct.

Also correct. IE7 and lower incorrectly let you set width, height and padding on display:inline elements just like they were inline-block – whereas the rest of the world does not.

It’s a seldom used selector hack that seems to only target IE7 or lower. It’s actually a bug in those browsers, but since microsoft doesn’t seem to be fixing those bugs, it’s fine. Just like “* html” for IE6 or lower.

A lot of people will bloat out the markup with IE conditionals using a separate file for those – I find that harder to work with and a waste of bandwidth… so I use !ie for IE7/lower and * html for IE6/lower… Usually I never actually need them in my own layouts, because I don’t do things that need such hacks in the first place. If I do resort to it, I use it once MAYBE.

There’s a whole slew of selector hacks out there - use them sparingly, you never know when they might break.
CSS Hacks

Still, the older ones that are IE7/lower are pretty much written in stone, and being they are incorrect behaviors no new browser should ever accidentally behave that way.

Jason must be having a rare off-day as that information isn’t quite correct :slight_smile:

All that will happen with Jasons code is that IE6 and 7 will get display:inline which means that dimensions will not be applied (unless in quirks mode).

IE7 and under only understand display:inline-block when used on inline elements but not when used on block elements. Indeed it would seem that the inline-block value is merely a “haslayout trigger” and all inline elements will behave as inline-block if they have “haslayout” which can be triggered with “zoom” or indeed any property that applies haslayout to inline elements (such as writing-mode or indeed inline-block itself).

Therefore to make block elements behave like inline-block elements in IE7 and under you must set them to display:inline and ensure that they have haslayout - preferably with zoom or inline-block itself. However if you use inline-block as the haslayout trigger then you must put it in a separate rule otherwise the display:inline will negate it (see [URL=“http://ago.tanfa.co.uk/archives/300.html”]Claires explanation of this trip switch trigger ).

So to make it easier to use we can use these methods as follows to get inline-block behaviour in IE7 and under.


span{display:inline-block}/* works for all*/

li {display:inline-block}/* sets haslayout*/
* html li{display:inline}/*IE6 -  makes it inline but haslayout is still preserved which means it behaves like inline-block*/
*+html li{display:inline}/*IE7 -  makes it inline but haslayout is still preserved which means it behaves like inline-block*/


Or if you don’t mind invalid code you could do something like this:


li {
    display:inline-block;
    *display:inline;/* only ie6 and 7 see this due to hack*/
     zoom:1.0;
}


Remember all that’s needed for IE7 and under to work is for the element to be inline (either by default or by setting its display to inline) and to have haslayout. The inline-block in the above code is redundant for <IE7 - It merely gets display:inline and haslayout. (This is not to be confused with the trip swich trigger effect mentioned previously.)

oh brother… every time I think I’ve learned everything there is to learn about this whole issue of block-vs-inline and li’s… I get stumped again… so:

meaning, if you don’t need to apply dimensions you can use this ok and it will work for IE6+7… but:

in other words, for IE6+7 you use display:inline-block to convert inline elements to block elements, but you can’t use display:inline to convert block elements to inline elements… correct??? but you can use the hacks you mention and this will work fairly reliably for IE6+7??

so this is the page in question:
my friend’s page
yesterday when I looked in IE7 (the computer at the gym was running IE7, fortunately…) the global-nav links across the top were also messed up…

so applied your hack…

your hacks are in lines 48-49, 58-59 and 69-70 in css:
http://andreahegeman.com/css/style.css
(now for the first one, since am not setting dimensions (line 47 in css)

div#header ul li {display:inline; } 

should work for all browsers? but it wasn’t working yesterday on IE7…

could someone reading this with the capability pls test this pg on IE6 & 7… (and one of the gallery pgs, for the gallery text-links at top of each pg…)
thank you very much…

on a more general note, given all this, and the fact that now I can’t always test on IE6+7, I think from now on, especially if I know all li’s will be same height, I will do with floats…

any issues I should expect for IE6+7 if I use simple floats with left/right margins?

thank you very much…

(PS: the concept of haslayout still confuses me… I’ve never been able to fully grasp what this ‘haslayout’ is exactly… “makes it inline but haslayout is still preserved which means it behaves like inline-block” not sure what you mean… )

No inline-block turns inline elements into elements that display as an inline-block (not display:block) - they are different things. But yes you can use it on elements that are natively inline in IE without the need for hacks.

but you can’t use display:inline to convert block elements to inline elements… correct??? but you can use the hacks you mention and this will work fairly reliably for IE6+7??

No you can’t turn block elements into inline-block elements in IE7 and under by using display:inline-block. You have to use the hacks I mentioned.

You seem to be misunderstanding the display values a little and there are three values that we are talking about as follows (although there are many more):

display:inline
display:inline-block
display:block

I also note that in your main stylesheet you have this:


body li {
    display:inline-block;
}

It is unlikely that you want all lists top be inline-blocks so I would remove that. Lists are display:list-item by default which is a kind of block display but with markers. Otherwise all your lists will be horizontal which is rarely what you want. Just code them on a case by case basis as required.

so this is the page in question:
my friend’s page
yesterday when I looked in IE7 (the computer at the gym was running IE7, fortunately…) the global-nav links across the top were also messed up…

so applied your hack…

your hacks are in lines 48-49, 58-59 and 69-70 in css:
http://andreahegeman.com/css/style.css
(now for the first one, since am not setting dimensions (line 47 in css)

div#header ul li {display:inline; } 

should work for all browsers? but it wasn’t working yesterday on IE7…

That would set IE7 to inline-block because of the previous global rule for body li{display:inline-block} that I mentioned above where haslayout was set using inline-block.

could someone reading this with the capability pls test this pg on IE6 & 7… (and one of the gallery pgs, for the gallery text-links at top of each pg…)
thank you very much…

That seems to be working in Ie7 and under for me ok anyway.

on a more general note, given all this, and the fact that now I can’t always test on IE6+7, I think from now on, especially if I know all li’s will be same height, I will do with floats…

any issues I should expect for IE6+7 if I use simple floats with left/right margins?

thank you very much…

You can’t center floats which is usually why inline-block is used instead (and when elements are a different height because floats will snag).

When using floats you need to watch out for the double margin bug in IE6 where the side margin will be doubled if the edge is adjacent to the containing block. The fix is to add display:inline also which cures the bug (but is actually nonsense as floats have a block display by default and cannot be changed with css).

(PS: the concept of haslayout still confuses me… I’ve never been able to fully grasp what this ‘haslayout’ is exactly… “makes it inline but haslayout is still preserved which means it behaves like inline-block” not sure what you mean… )
Haslayout is clearly defined in the reference here with advice on its use and the “haslayout trip switch” effect was clearly defined in Claire’s page I linked to. The display:inline-block applies haslayout to an element (it’s only real use in IE) but the element maintains haslayout even when the display is set back to display:inline in a new rule. Haslayout is lost if the display:inline exists in the same rule as the display:inline-block - that’s the trip switch effect Claire mentions in the link I posted.

I notice that you are mixing a lot of properties that don’t go together so it seems you are still a little confused. If an element is absolutely positioned then it can’t be floated because absolute positioning wins out.

If an element is floated then it can’t be display:inline-block because float wins out.

Actually it’s just not something I use in building pages anymore… because if the layout “demands” it, I change the layout. Part of why I do the layout in CSS, THEN start up the paint program to hang graphics on it – instead of the “let’s design a layout before we even have semantic markup” asshattery.

yes actually that’s what I meant: convert to display:inline-block…:wink:

Yes I did remove that… thank you…

thank you very much…

that’s right… I remember that one… and if you can’t test in IE6+7 you can’t really deal w/that one… :wink: oh man…

ok, will refer to those… thank you very much…

[QUOTE=Paul O’B;4927059]I notice that you are mixing a lot of properties that don’t go together so it seems you are still a little confused. /[QUOTE]

I’m actually not confused at all about those properties… or do I have elements where i combine float & position properties??? because I know you can’t combine those… (and, can you, for example, combine float and display (as in float:right; display:none; ) ???

obviously I do need to study this still a little more… thank you very much for your help…

Dude, where’d you find that? I’ve never seen that anywhere either!

I can’t really think of a use for it but it’s good to know it exists. !ie lawlz.

It’s not that you can’t use them together, but often when you do, since one will usually override the other, you end up with code that Does Nothing (unless you’re later overriding them and just wanted the default display state listed earlier in the stylesheet).

One of the oldest pages online about CSS hacks in the first place. Webdevout’s page on the subject.

CSS Hacks

Internet Explorer 7 fixed one of the issues with the !important identifier, but it still has problems when the identifier has an error in it. If an illegal identifier name is used in place of important, Internet Explorer 7 and below will handle the property normally instead of failing. Therefore, in any style declaration block, you can include properties intended to only apply to Internet Explorer and add an !ie identifier. Almost any word can be used in place of ie.

The !ie identifier allows the property to be applied in IE 7 and below. It may or may not work in future versions. Warning: this uses invalid CSS!

It’s like the one after it on that page – HTML* – I’m not sure if that’s fixed in later versions of IE or not though. Still:

html* #mainMenu

would target IE only (not sure where the cutoff is), just as

  • html #mainMenu

Only works in IE6/lower.

Invalid CSS, and that’s why it only works in IE as they repeatedly try to take… shortcuts in interpreting CSS selectors to try and speed up the browser.

There are a lot of CSS selector bugs… some of them, like say the one to target older versions of gecko:

html:not([lang*=“”])

I often wonder how long people had to play around in the browsers to even find.

I’ve never really been a big fan of selector hacks – but given the alternatives are a dozen times worse… Like anything else it’s good to know as many different ways of doing it as you can – as no one solution can be the end-all be-all. More tools in the toolbox, less likelyhood of acting like Uncle Red and using a hammer to drive screws… since you’ve got slotted, phillips, torx, hex… but Red Green? He likes flathead. (BAM, BAM, BAM)

I often wonder how long people had to play around in the browsers to even find.

Me too.

Yes you have them here (marked in bold):


body.galleries ul#photos li a span {
   [B] display:inline-block;
    position:absolute;[/B]
    text-align:center;
    top:233px;
    left:0;
    font-size:14px;
    width:100%;
}
#thumbs {
    margin:0 auto 60px auto;
    width:100%;
    overflow:auto; /*position:absolute;top:0;left:0;*/
}
#thumbs a {
    margin:0 7px 0 0;
    background-position:4px 4px;
    background-repeat: no-repeat;
    width:88px;
    height:88px;
  [B]  float:left;
    display:inline-block;[/B]
    border:solid 1px #e8d4b1;
    text-indent:-9999px;
}


In the first rule position:absolute wins ot and the dfisplay:inline-block is redundant.

In the second example the float wins out and the display:inline-block is again redundant.

that’s right… I remember that one… and if you can’t test in IE6+7 you can’t really deal w/that one… :wink: oh man…

Yes you can fix it by ensuring that display:inline is added to all floats that are adjacent to their parents side edges which should be pretty obvious which ones they are. If in doubt add it to all floats and you can’t go wrong except that you will be adding extra code where none is necessary :).

ok… so I can’t do position:absolute on an element that is inline-block??? hmmmm… there’s a reason why the code for those gallery links a bit weird… I had done the obvious thing and used padding so the plain text falls below the background images… I mean on this page… but then I looked at it in IE7 the other day and they looked absolutely horrible… now you know that if you use padding-top you have to subtract from the overall height of element to calculate the height, right? (that’s one of the very few things I don’t like at all about CSS, how you have to subtract from dimensions of element when using padding, but oh well… ) so what I tried was give those elements a height of 22px, to make up for the padding-top 233px; now all browsers, even the modern ones, didn’t like that at all, it looked ghastly… (and it’s a perfect example of why I wish padding values didn’t have to be subtracted from dimensions of elements…) I just wanted it to be inline-block so I can do with:100% so I could center the text inside… oh man… so inline-block (at least in modern browsers where it isn’t ignored) won’t take on an element with position:absolute???

so you can’t do inline-block for floated elements? oh brother… I need to study this whole issue more, if you have good relevant links please post them…

yes but since those thumbnails are links they have to be either block or inline-block so I can give them dimensions… so what do you do when you need to float links that have to be block elements? oh man… the longer this thread gets the more ignorant I feel… OH BROTHER… I need to experiment a lot more with this… only prob is I can’t test on IE6+7 (need to find what is best thingie (pc/windows thingie) to purchase to test on that messed-up browser on the mac…)

thank you all very much for your help…

If you list two conflicting display states, one of them has to be rendered. Browser has to pick one. So there are rules on which do which.

If you absolutely position something, it gets (mostly) block context (except dimensions) and gets placed relative to nearest positioned ancestor, or if there is none, the viewport. Meaning float and display have to be ignored.

When you float something, it gets (mostly) block context and so browser has to ignore if you say display: anything. Position absolute overrides float but you can have something relatively positioned and floated. Relative positioning is kind of special though… doesn’t do what you might think it does.

So the browser just follows a list of overriding rules when you give it conflicting advice and it just follows those rules.

ok, I corrected errors mentioned in in Paul’s post…

could someone who has the capability, pls look at these pages on IE6+7?

galleries to make sure those gallery links still look ok, and one of the [URL=“http://andreahegeman.com/galleries/evolution/”]gallery pages please, to make sure thumbnails still look ok?

(still a bit confused b/c my understanding is that span is an inline element, and to give it width of 100% it has to be block element, yes? but you’re saying the positioning absolute makes it a block element? is this correct? and for the #thumbs a, floating them makes them block elements?

thank you again…

Re-read what I said :slight_smile: The position:absolute wins out and the display:inline-block is ignored. The element will be absolutely placed (removed from the flow) and therefore will sit wherever you place it. Absolute elements basically create block display elements that are removed from the flow but shrinkwrap their content. You don’t need to add display properties to absolute elements.

I gave you a link to a table showing exactly which properties will be applied in these circumstances.

so you can’t do inline-block for floated elements? oh brother…

Why would you want to? They are mutually exclusive and have different behaviours. If the element is floated then there is no need for inline-block unless you want the ability to center the elements and you don’t want content to wrap and in which case you would use inline-block.

yes but since those thumbnails are links they have to be either block or inline-block so I can give them dimensions… so what do you do when you need to float links that have to be block elements?

Floated elements display as block boxes by default (as I mentioned before) so you need do nothing as they will take dimensions by merely being floated.

Take a step back and re-read this thread as al the information you need has already been said or linked to.:slight_smile:

could someone who has the capability, pls look at these pages on IE6+7?

They seem to still look ok in IE7 :slight_smile:

yes I definitely need to study this entire thread… and read further on this issue…

thank you very much to all for your help…