<分区>
编辑问题以包含 desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem .这将有助于其他人回答问题。
关闭 7 年前。
标签 javascript html css
<分区>
编辑问题以包含 desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem .这将有助于其他人回答问题。
关闭 7 年前。
我无法让我的 #supportive
DIV 位于它前面的 div 下方,我不确定为什么:
我打算通过在 javascript 中动态添加一个“margin-top”来解决这个问题,因为 slider 的高度会根据屏幕尺寸而变化,但是我确定在 CSS 中一定有办法做到这一点?
尝试将元素 float 到彼此“下方”时,绝对定位会成为问题吗?
这是网站:https://dl.dropboxusercontent.com/u/4469116/new/index.html (要解决问题,请点击“元素”,然后点击左上角的第一张图片)。
最佳答案
您的 slider 具有绝对定位,因此您必须通过应用绝对定位元素高度的 margin-top 来补偿其高度,在本例中约为 380px
将此 CSS 添加到该 View 的样式表中:
#supportive {
margin-top: 380px;
}
此外,正如我所见, float 没有做任何事情,因此您应该能够将其删除
如果您不希望您的解决方案是固定的,那么使用当前标记的简单方法是为 slider 提供一个百分比高度,然后为#e #supportive 节点提供一个顶部边距
.slider {
height: 30%;
width: auto;
}
#supportive {
margin-top: 30%;
}
或者您可以将 .slider
放在一个单独的容器中,并为容器指定您想要的尺寸。这样,您的节点将始终如您所愿地位于底部,并且 .slider
的容器将处于文档的自然流动中。
关于javascript - DIV 不会位于 slider 下方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36345599/