【发布时间】:2019-03-10 06:32:34
【问题描述】:
我有一个使用 height: 50vh; 的 div,但无论我尝试什么,我都无法让其中的内容停止溢出。在 div 内部,我有另一个 div,它使用背景图像并保持特定的纵横比……它还使用溢出滚动。
我想要做的是让顶部 div 中的内容在浏览器调整大小时调整大小,同时保持相同的纵横比。
请告诉我这是否可行,如果可行,我该如何实现。
谢谢!
这是我目前所拥有的一个例子。
Codepen:https://codepen.io/anon/pen/LaLqNZ
body,
html {
padding: 0;
margin: 0;
}
#wrap {
width: 100vw;
height: 100vh;
display: inline-block;
margin: 0;
padding: 0;
}
#top {
width: 100vw;
height: 50vh;
display: inline-block;
background: blue;
padding: 20px;
box-sizing: border-box;
}
#bottom {
width: 100vw;
height: 50vh;
display: inline-block;
background: green;
}
.one {
max-width: 450px;
margin: auto;
}
.two {
padding-top: 73%;
display: block;
margin: 0;
background-image: url(https://i.imgur.com/OQL0NR3.png);
background-size: cover;
-moz-background-size: cover;
background-position: center;
position: relative;
}
.three {
position: absolute;
top: 5.3%;
right: 4%;
bottom: 23.5%;
left: 4%;
}
.four {
max-height: 100%;
overflow: scroll;
}
.four img {
max-width: 100%;
display: block;
}
<div id="wrap">
<div id="top">
<div class="one">
<div class="two">
<div class="three">
<div class="four"><img src="https://i.imgur.com/4yBw2n4.jpg"></div>
</div>
</div>
</div>
</div>
<div id="bottom">
<h1>Sample Text</h1>
</div>
</div>
【问题讨论】:
-
我在此处提供的源代码或codepen 链接中看不到
max-height: 50vh;的任何用法。 -
@NewToJS 对不起,我的意思是说高度:50vh;.
-
当你说 “我要做的是让顶部 div 内的内容在浏览器调整大小时调整大小,同时保持相同的纵横比。” 你的意思是电脑显示器应该用它调整大小吗?
-
@NewToJS 是的,我想调整显示器的大小。调整浏览器宽度时显示器正确显示...但调整浏览器高度时显示器无法正确显示。我希望我解释得没错。
标签: javascript jquery html css responsive-design