2017-05-30 21 views
0

我想在引導中創建兩個並排窗格。整個頁面的高度應該爲100vh,頁面沒有滾動條。如何強制元素以適應內部100vh

但是左側內容標籤中應該有一個滾動條。取而代之的是我沒有考慮到我的h1元素的高度,左邊的內容和整個頁面都有一個滾動條。我怎樣才能做到這一點,唯一的滾動條是在左側內容的框中。對不起,我的糟糕的工作解釋,但如果你訪問小提琴它將是非常明顯的。

的jsfiddle:https://jsfiddle.net/7uauho0d/1/

HTML:

<div id="pg-container"> 


    <h1> 
    TITLE AT TOP 
    </h1> 

    <div class="col-xs-8" id="left"> 
    <h1>LEFT CONTENT</h1> 
    <h1>LEFT CONTENT</h1> 
    <h1>LEFT CONTENT</h1> 
    <h1>LEFT CONTENT</h1> 
    <h1>LEFT CONTENT</h1> 
    <h1>LEFT CONTENT</h1> 
    <h1>LEFT CONTENT</h1> 
    <h1>LEFT CONTENT</h1> 
     <h1>LEFT CONTENT</h1> 
    <h1>LEFT CONTENT</h1> 
    <h1>LEFT CONTENT</h1> 
    </div> 

    <div class="col-xs-4" id="right"> 

    <h1> 
RIGHT CONTENT 
RIGHT CONTENT 
    </h1> 
    </div> 
</div> 

CSS:

#pg-container { 
    height: 100vh; 
} 

#left { 
    overflow-y: scroll; 
    background-color: lightgrey; 
    /* When I specify 100% here, I expect it to take into account the <h1> at the top 
    so that this element is the height of the viewport minus the height of the title at 
    the top. I expect only 1 scrollbar, the one inside left content, there should be no 
    scrollbar for the page*/ 

    height: 100%; 
} 

#right { 
    height: 100%; 
} 
+0

在擁有'height:100vh'的父容器上設置'overflow:hidden' –

回答

1

隨着flexbox利用率,有height: 100vh應該工作在父容器上設置overflow: hidden

檢查此琴:https://jsfiddle.net/7uauho0d/7/

+0

感謝您的嘗試,但我的問題比這更復雜。標題應始終可見。這是關於獲得適當的高度左邊的內容框 – Keatinge

+0

檢查更新的答案 –

+0

完美的謝謝! – Keatinge

0

添加overflow-y: hidden到外的div:

#pg-container { 
    height: 100vh; 
    overflow-y: hidden 
} 

如果要禁用水平滾動,以及,你可以只使用overflow: hidden代替。

頂部的標題欄應始終可見。儘管您始終可以通過position: absolutetop: 0執行此操作。

+0

不是我想要做的,請訪問我發佈的小提琴。 – Keatinge

+0

你的問題不是很清楚。例如,你提到在你的小提琴中,尺寸不是你h1元素的高度。我確實引用了你的小提琴,幾乎每個子元素都是h1元素。我不能假設你低估了我的答案,但如果你這樣做了,答案不能回答你的問題並不完全是我的錯。您應該承擔發佈不明確問題的責任。 – CryptoCat

相關問題