[英]100vh going over viewport only on laptop
I'd like to use #conA as a hero section and have #conA's height to fill the entire viewport (so #conA height:100vh).我想使用#conA 作为英雄部分,并让#conA 的高度填满整个视口(所以#conA 高度:100vh)。 It's working correctly on tablet, but on laptop, it looks like #conA's height takes up much more than viewport.
它在平板电脑上正常工作,但在笔记本电脑上,看起来#conA 的高度比视口占用的要多得多。
Son on tablet it looks correctly: enter image description here儿子在平板电脑上看起来正确:在此处输入图像描述
But on laptop, it looks like: enter image description here (note that I tried putting a blue border to #conA, and it's way taller than viewport)但是在笔记本电脑上,它看起来像:在此处输入图像描述(请注意,我尝试在#conA 上设置蓝色边框,它比视口高得多)
What I'd like it to look like instead is this: enter image description here我希望它看起来像这样:在此处输入图像描述
Is there a way to fix this?有没有办法来解决这个问题?
<section id="conA">
<div class="container">
<div id="heroText">
<div id="text-fixed">lorem ipsum</div>
<div id="text"></div>
</div>
<div id="images"></div>
</div>
</section>
#conA {
height: 100vh;
}
#conA .container {
margin-left: auto;
margin-right: auto;
display: block;
}
#heroText {
color: #56525E;
}
#conA #text {
display: inline;
}
@media (min-width: 600px) and (max-width: 959px) {
#conA .container {
width: 70%;
}
#conA {
min-height: 800px;
position: relative;
}
#heroText {
line-height: 1.7;
font-size: 28px;
text-align: center;
position: absolute;
width: 70%;
top: 20%;
left: 50%;
-webkit-transform: translate(-50%, 0);
-ms-transform: translate(-50%, 0);
transform: translate(-50%, 0);
}
#conA #images {
text-align: center;
position: absolute;
top: 35%;
left: 50%;
-webkit-transform: translate(-50%, 0);
-ms-transform: translate(-50%, 0);
transform: translate(-50%, 0);
-webkit-transform: translate(-50%, 0);
-ms-transform: translate(-50%, 0);
width: 90%;
}
#conA #images img{
width: 13em;
height: auto;
}
}
It feels like there is more to it than you have provided.感觉它比你提供的更多。 However, my observations are as such
然而,我的观察是这样的
height:100vh
try using max-height: 100vh
.height:100vh
尝试使用max-height: 100vh
。 It would limit your #conA to 100vh only.<meta name="viewport" content="width=device-width, initial-scale=1.0">
added inside your tag.<meta name="viewport" content="width=device-width, initial-scale=1.0">
。 Finally, it very much depends on type of screen.最后,它在很大程度上取决于屏幕的类型。 The Pixel DPI (density per inch) for your Tablet may be something very different from your system.
您的平板电脑的像素 DPI(每英寸密度)可能与您的系统非常不同。 Read more about Pixel density here: https://material.io/design/layout/pixel-density.html
在此处阅读有关像素密度的更多信息: https://material.io/design/layout/pixel-density.html
do you really need a @media?你真的需要@media 吗? here is your simplified code with flexBox.
这是您使用 flexBox 的简化代码。 is the rendering as expected?
渲染是否符合预期?
#conA {
height: 100vh;
border:blue 5px solid;
}
#conA .container {
display:flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
#heroText {
background: red;
line-height: 1.7;
font-size: 28px;
text-align: center;
width: 70%;
margin-top:20vh;
}
#conA #images {
background: yellow;
text-align: center;
margin-top: 1em;
width: 100%;
}
#conA #images img{
width: 13em;
height: auto;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.