【发布时间】:2020-09-15 17:56:17
【问题描述】:
您好,在我的项目中,我刚刚设置了一个带有 div 的卡片元素,其中包含顶部的图像和下面的文本。我的问题是当设置为 100% 高度时包含图像的 div 使用卡片的高度而不是父 div 的高度。有谁知道修复方法是什么?
css:
.Cards {
position: absolute;
width: 85%;
height: 85%;
background: white;
box-shadow: 0 14px 28px rgba(0, 0, 0, 0.1), 0 10px 10px rgba(0, 0, 0, 0.2);
margin-left: auto;
margin-right: auto;
margin-top: 20%;
left: 0;
right: 0;
text-align: center;
border-radius: 7px;
overflow: hidden;
background: #7510f7;
display: flex;
flex-direction: column;
.image-iframeContainer {
display: flex;
width: 100%;
//删除此高度值或将其设置为 100% 会破坏它/不起作用
height: 50vh;
background: #141c3a;
overflow: hidden;
img {
width: auto;
height: auto;
max-width: 100%;
max-height: 100%;
object-fit: cover;
background-repeat: no-repeat;
margin: auto;
}
iframe {
position: absolute;
margin: 0;
top: 0;
left: 0;
width: 100%;
height: 100%;
border: 0;
}
}
这是我的沙盒,您可以看到: https://codesandbox.io/s/sleepy-sunset-jqjst?file=/src/styles.scss
【问题讨论】:
标签: html css reactjs sass height