2016-09-24 60 views
-1

我想讓身體固定100%的高度和身體內的主要div可滾動和有一定的餘量。事情是這樣的:bootstrap可滾動div進身體高度100%

enter image description here

+0

告訴我到目前爲止你已經嘗試過的代碼? –

+0

我找到了一個使用jquery的解決方案;我得到身高onload和調整大小減去100px(填充)。無論如何謝謝 –

+1

使用css'calc()'比jquery更容易!學習它以使代碼更清晰。如果你使用jquery,那麼這段代碼必須運行onload和onresize,更困難。 –

回答

1

你真的不需要引導這個!

在你的情況下不能運行的代碼段,這是CodePen筆:http://codepen.io/kranzy/pen/bwqWbo

body { 
 
    margin: 0; 
 
} 
 
.full { 
 
    position: absolute; 
 
    width: 100%; 
 
    height: 100%; 
 
    background-color: red; 
 
    overflow: hidden; 
 
} 
 
.inside { 
 
    position: relative; 
 
    /* some bit of margins */ 
 
    top: 50px; 
 
    left: 50px; 
 
    /* calculate the width, if not, weird effect. */ 
 
    width: calc(100% - 50px * 2); 
 
    height: calc(100% - 50px * 2); 
 
    /* 50px * 2 because 50px is just enough for the .inside div's width and height not to fall out of screen. */ 
 
    /* make it like your image */ 
 
    background-color: blue; 
 
    overflow: auto; 
 
}
<div class="full"> 
 
    <div class="inside"></div> 
 
</div>

+1

你想添加一些文本到內部塊嗎?當滾動條出現時,代碼片段會更清晰。 –

+0

我想我不應該因爲你將不得不刪除lorem ipsum文本來使用代碼。但是,如果重要,隨時編輯我的答案。 –

0
<div class="main" style="background-color:red; height:100vh; float:left; width:100%;> 

    <div class="wrapper" style="width:1170px;margin:0 auto"> 
    <div class="main-text" style="float:left; width:100%; background-color:blue;"> 

</div> 

<div> 

</div>