0

I've studied css styles of Google Docs, and I have noticed there such a thing:

.goog-inline-block {
    position        : relative;
    display         : -moz-inline-box;
    display         : inline-block
}

* html .goog-inline-block {
    display         : inline
}

*:first-child + html .goog-inline-block {
    display         : inline
}

html>body .goog-inline-block {
    display         : -moz-inline-box;
    display         : inline-block
}

I understand what this .goog-inline-block class should mean, but this code arose questions for me:

  • Why are there so much declarations for a simple class?
  • Why does simple .class-name declaration differ from * html .class-name declaration?
  • What is this crafty construction *:first-child + html .class-name doing?
0

1 Answer 1

4

This rule:

* html .goog-inline-block {
    display         : inline
}

defines a style for IE6. In IE6's document model, there's a mysterious root element that contains html, so this selector takes advantage of that fact using the * html hack.

This rule:

*:first-child + html .goog-inline-block {
    display         : inline
}

defines a style for IE7. In IE7's document model, there's no more root element above html, but there's another one before it, which is what's targeted by the *:first-child + html selector.

This rule:

html>body .goog-inline-block {
    display         : -moz-inline-box;
    display         : inline-block
}

defines styles for IE7+ and other browsers. The child selector > isn't supported by IE6, so it never sees this rule. -moz-inline-box is actually the same as inline-block, but meant for Firefox 2 and older as those versions don't support inline-block.

There are so many declarations for that class because different browsers have problems with the display: inline-block style, so hacks and workarounds are needed for these browsers.

3
  • So, .class-name { display: inline; } isn't crossbrowser, is it? I can admit that IE6 needs exceptions, but do other browsers too? Commented Aug 25, 2011 at 9:43
  • @Innuendo: The cross-browser issue doesn't lie in .class-name, but in display: -moz-inline-box and display: inline-block.
    – BoltClock
    Commented Aug 25, 2011 at 9:44
  • Sorry for * :first-child - I've removed space (it's because of manually beautifying that code). Ok, so issue is exactly in display: inline-block property, but not in .class-name - I've understood, thanks Commented Aug 25, 2011 at 9:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.