views:

777

answers:

3

I have an element positioned outisde its parent via negative margins, like this:

<style>
.parent {
    height: 1%;
}

.element {
    float: left;
    margin-left: -4px;
}
</style>

...

<div class="parent">
    <div class="element">Element</div>
</div>

In Internet Explorer 6, the part of .element positioned outside of its parent element is clipped, i.e. invisible, hidden, cut off. How do I fix this?

+4  A: 

Assign position: relative; to .element, like this:

<style>
.parent {
    height: 1%;
}

.element {
    float: left;
    margin-left: -4px;
    position: relative; /* Fixes clipping issue in IE 6 */
}
</style>

...

<div class="parent">
    <div class="element">Element</div>
</div>

This is only necessary if the parent element hasLayout (which is too big a can of worms to get into here).

Paul D. Waite
Awesome i've been struggling with this issue for days!!! finally got a fix that works :)
Alex
Interesting. I've had this problem several times before and indeed spent hours trying various changes in the CSS to no avail. This seems to do the trick.
jwal
@jwal: excellent, glad it’s helped.
Paul D. Waite
A: 
<style>
.parent {
    height: 1%;
    overflow: auto;
    _zoom: 1; /*ie6 hack forces has layout*/
}

.element {
    float: left;
    margin-left: -4px;
}
</style>
gabriel
That doesn’t seem to fix the issue. I think `height: 1%` should force hasLayout on `.parent` anyway; you shouldn’t need `zoom: 1` as well.
Paul D. Waite
A: 

This happens with negative margins combined with floats in IE6.

If you can, get rid of the float:

.element {
   float: none:
   zoom: 1;
}
Eystein