【发布时间】:2019-04-28 21:56:01
【问题描述】:
我已经查看了类似的问题并尝试删除 position 属性,但不幸的是没有用。
我有一个容器,里面有 2 个 div,这两个 div 都包含一个图像。图像显示正确,但整个容器的高度为 0px。这是打开开发者控制台的图像:https://gyazo.com/277d635619eb80d2d3f63a1c28c80314 这发生在尝试使图像响应宽度:100%;和高度:自动;
#landing-images {
width: 100%;
height: auto;
margin-top: 10%;
margin-bottom: 5%;
border: solid 2px black;
}
.leftLanding {
/*position: relative;*/
width: 80%;
float: left;
}
.rightLanding {
/*position: relative;*/
width: 80%;
float: right;
}
.landingImage {
width: 100%;
height: auto;
}
<div id="landing-images">
<div class="leftLanding">
<img class="landingImage" src="http://www.hlgjyl888.com/data/wallpapers/57/WDF_1035782.png">
</div>
<div class="rightLanding">
<img class="landingImage" src="http://www.hlgjyl888.com/data/wallpapers/57/WDF_1035782.png">
</div>
</div>
【问题讨论】:
-
那么你的问题是什么?
-
@karimyafi 如果高度是自动的,为什么它不等于其内容的高度?或者“如何使高度等于其内容”?
-
隐藏溢出:)
-
溢出:隐藏
-
浮动子元素会从文档流中删除父元素的期望行为,并且父元素将折叠,因此您只需要添加溢出属性,如我在回答中所述。