hasLayout Block vs. hasLayout Zoom

2019-07-04 04:41发布

问题:

I've been going through the online reference of compass when I ran into this page: http://compass-style.org/reference/compass/utilities/general/hacks/

On this page, there apear to be 2 methods to implement a has-layout hack for IE. One of them sets zoom: 1; The other sets display: inline-block;, and then sets it back to display: block; again.

What the manual doesn't explain is what's the difference between these two.

Is there any difference? Are there particular situations where you would prefer to use one or the other?

回答1:

The first method:

@mixin has-layout-block {
  @if $legacy-support-for-ie {
    // This makes ie6 get layout
    display: inline-block;
    // and this puts it back to block
    & {
      display: block; } } }

will compile to something like:

selector {
    display: inline-block;
}
selector {
    display: block;
}

And the second method:

@mixin has-layout-zoom {
  @if $legacy-support-for-ie6 or $legacy-support-for-ie7 {
    *zoom: 1; } }

will compile to something like:

selector {
    *zoom: 1;
}

Both methods will successfully give an element hasLayout, so purely from that perspective it doesn't matter which you use.

The first method will pass validation, whereas the second method will not. However, the validation failing in the second method is a complete non-issue; the hack used is "safe".

I use the second method everywhere because it's shorter and doesn't involve two rules.

It's not really worth worrying about (IE6/7 are dying), but if you want more information read this and this.