ie7 - relatively positioned div does not scroll in

2019-04-14 23:34发布

问题:

I have a div with a scrollbar. Within it, I have various elements, one of which is an link with display:block and position:relative; Inside of this link are an img with default positioning, and an h3 tag which is supposed to appear over the top of that img, with position:absolute. When I scroll the DIV, other things scroll properly, but these elements and their contents stay fixed. Any ideas on how to solve this bug?

Here's a fiddle, and the approx. code is below:

http://jsfiddle.net/Z987x/

<a class="slider_link" data-ident="herb-garlic-roast-tenderloin" href="http://superfadlabs.com/clients/carapelli/recipes/herb-garlic-roast-tenderloin">


  <img class="slider_image" src="http://superfadlabs.com/clients/carapelli/images/sections/recipes/share_carousel_images/tenderloin.jpg" alt="Herb &amp; Garlic Roast Tenderloin" style="
    left: 0px;
    top: 0px;
    display: block;
">

  <h4>Herb &amp; Garlic Roast Tenderloin</h4>
</a>

a.slider_link { 
    width:190px; height:220px; position: relative; display: block; margin-bottom:10px;
    h4{ .cubano; font-size:1.8em; position: absolute; color: #fff; top:11px; left:14px; line-height: 110%; padding-right:10px; height:40px; overflow: hidden; }
}

回答1:

The quick and dirty fix would be to add position:relative; to the container with the overflow:auto; property.

Though, I would strongly suggest you consider rethinking your layout to not rely on position absolute/relative and instead use floats if possible.

Updated jsfiddle: http://jsfiddle.net/Z987x/1/