[英]Container wont fit 100% of screen
I am trying to have a typical forum look to my website but the container of my content won't fit to 100% of my page height. 我试图在我的网站上显示一个典型的论坛外观,但我的内容容器无法适应我的页面高度的100%。
I have tried using height: 100vh;
我试过用height: 100vh;
and all the others I can find. 和所有其他我能找到的。
My CSS is 我的CSS是
body {
font-family: Verdanna, Arial, Helvetica, sans-serif;
background-repeat: no-repeat;
background-attachment: fixed;
color: #f2efe8;
margin-right: auto;
margin-left: auto;
font-size: 20px;
background-image: url("../resources/bokeh.jpg");
background-size: cover;
padding: 0 10px 0 10px;
height: 100%;
min-height: 100%;
margin: 0;
}
header {
font-family: Verdanna, Arial, Helvetica, sans-serif;
text-align: center;
font-weight: 700;
padding: 4px;
background: rgba(0, 0, 0, 0.2);
}
div.container {
width: 1000px;
margin: auto;
background-color: rgba(0, 0, 0, 0.3);
top: 0;
bottom: 0;
}
If you add 100% height to the body & html and min-height: 100% to the container you'll be good to go (unless I've misunderstood the question). 如果您将100%的高度添加到body&html和min-height:100%添加到容器中,那么一切都会好起来的(除非我误解了这个问题)。
body, html {
height: 100%;
}
.container {
min-height: 100%;
}
Full code example: https://codepen.io/raptorkraine/pen/ZKZeLz 完整的代码示例: https : //codepen.io/raptorkraine/pen/ZKZeLz
Another approach 另一种方法
Create a wrapper with it's own id or class and set it with these css properties: 使用自己的ID或类创建包装器,并使用以下CSS属性进行设置:
.background {
position:fixed;
top:0;
right:0;
bottom:0;
left:0;
background-repeat: no-repeat;
background-attachment: fixed;
color: #f2efe8;
background-image: url("../resources/bokeh.jpg");
background-size: cover;
z-index:-1;
}
This content will never scroll though. 该内容将永远不会滚动。
From my experience, you should want the page to be at least 100% height, but still increase if more content are added. 根据我的经验,您应该希望页面的高度至少为100%,但是如果添加更多内容,页面仍会增加。
html, body{
height: auto; /* This is applied by default, so it's not necessary to define it */
min-height: 100vh;
}
Here I use min-height: 100vh
instead of min-height: 100%
because otherwise the body will not take 100%, because the parent needs a fixed height for that. 在这里,我使用min-height: 100vh
而不是min-height: 100%
因为否则身体将不会占用100%,因为父级为此需要固定的高度。
Then, when you want a full screen container, don't try with height: 100%
, you can create a helper class for that: 然后,当您要使用全屏容器时,不要尝试使用height: 100%
,您可以为此创建一个帮助器类:
.vh-100{
height: 100vh;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.