javascript - DIV 不会位于 slider 下方

标签 javascript html css

<分区>


关闭 7 年前

我无法让我的 #supportive DIV 位于它前面的 div 下方,我不确定为什么:

enter image description here

我打算通过在 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;
}

Your slider has absolute positioning, therefore your must compinsate for its height by applying a margin-top of the amount of the absolutely positioned items height, in this case it was around 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/

上一篇:javascript - 如何使填充窗口的元素保持居中?

下一篇:jQuery sibling 方法和设置高度

相关文章:

javascript - C3 图表中的特定 JSON 值限制

JQuery Dialog 的 CSS 内容在换页时会保留

css - 停止在移动设备上自动播放背景视频

javascript - jquery iframe跨域动态高度

javascript - 这个本地存储代码有问题吗?

javascript - 为 slider 动态加载 css 背景图像

html - Firefox 无法识别复选框的背景图像

css - 转换复杂 SVG 组中嵌套元素的原点

java - 将连续的字符串数据拆分为所需的垂直输出

javascript - karma-jasmine 无法读取属性 'clearTimeout'