[英]How to set minimum height to the 100% of the viewing screen and half of the page?
我有一個頁面站點,其中第一部分的主要部分應該是查看器屏幕/瀏覽器大小的100%,第二部分的部分應該位於查看區域的下面,因此當用戶單擊鏈接時,頁面會向下滾動到第二部分部分。
我如何實現這一目標。,到目前為止,我已經嘗試過了,但是尚未將最小高度設置為100%
HTML:
<div class="container">
<div class="firsthalf">
this is the first part of the site
<a href="#help"> <i class="fa fa-question-circle fa-lg"></i>
<div class="notice">this is aligned to bottom of first half
</div></div>
</div>
<div class="container">
<div id="help" class="secondhalf">
<div class="col-md-8 col-md-offset-2">
<div class="well">
we are in second part of the site
</div>
<a href="#top" class="btn btn-default"><i class="fa fa-arrow-up "></i> Top</a>
</div>
</div>
</div>
CSS:
body, html {
height: 100%;
}
.firsthalf{
height:100%;
}
.notice{
margin-bottom:0%;
padding-bottom:5px;
}
.secondhalf{
margin-top:25%;
margin-bottom:50%;
padding-top:25px;
min-height:50%;
}
position: relative;
和position: absolute;
他們在這種情況下是你的朋友
body, html {
height: 100%;
}
.container {
height:100%; /* first make container full height */
}
.firsthalf {
height:100%;
border:1px solid #000;
position: relative; /* make parent div relative */
}
.notice {
padding-bottom:5px;
position: absolute; /* this does the base line trick */
bottom: 0;
right: 0;
}
視口高度(vh)您正在尋找高度:50vh; 或高度:100vh;
您可能會發現一些有用的選項:
vh(視口高度)vw(視口寬度)vmin(視口最小長度)vmax(視口最大長度)
http://stanhub.com/how-to-make-div-element-100-height-of-browser-window-using-css-only/
.secondhalf{
margin-top:25%;
margin-bottom:50%;
padding-top:25px;
height:50vh;
}
編輯:確保您需要支持的瀏覽器支持它。 http://caniuse.com/#feat=viewport-units
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.