html - CSS - 定位难题

标签 html css

我正在使用相对 div 中的绝对定位。代码如下:http://jsfiddle.net/32mq5v6L/1/

HTML

<div id="container">

    <div id="featured-posts">
        <div class="slide"><img src="http://alien.devprose.com/starwars/wp-content/uploads/2014/12/star-wars-droid.jpg" /></div>
        <div class="slide"><img src="http://alien.devprose.com/starwars/wp-content/uploads/2014/12/han-solo-1140x350.jpg" /></div>
    </div>

    <div id="other-content">
    Other Content
    </div>

</div>

CSS

#container { width: 100%; margin: 0 auto; background: #eee; }

#featured-posts { position: relative; width: 100%; height: auto;}
.slide { width: 100%; height: 20px; position: absolute; top: 0; }

#other-content { }

我的问题是 other-content div 出现在#featured-posts 下方,除非我对该容器应用设置的高度,但我不能这样做,因为目标是让所有这些响应。

我哪里错了?

最佳答案

如果您计划在定位容器之后放置 #other-content,则必须创建新的堆叠上下文才能将其移动到上方。因为它没有定位,所以一种方法是设置非常小的不透明度:

#other-content {
    z-index: 10;
    opacity: .99;
}

演示:http://jsfiddle.net/32mq5v6L/1/

关于html - CSS - 定位难题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27680625/

相关文章:

html - 网页上的悬停效果覆盖下拉导航栏

html - Jquery Mobile 中复选框部分的背景颜色

javascript - 如果 href 等于,jquery 隐藏元素

html - 有限 margin 汽车?

html - 带有 id 和 class 的 CSS 不显示类样式

CSS,更改背景颜色以补偿容器背景颜色

html - 在父 div 的底部有 float 按钮

javascript - 如何使用移动浏览器进行无缝音频循环?

python - lxml xpath 不工作

FF 和 Chrome 之间的 jQuery 区别