2017-05-26 61 views
0

使用Bootstrap 4和Flexbox,您如何實現帶有固定寬度左列和靈活右列的2列布局?Bootstrap 4帶固定和柔性寬度列的Flexbox

我沒有看到關於如何實現這一目標的文檔什麼...我能做到這一點很容易不夠用香草CSS,但我覺得我應該用引導,因爲我已經在拉。

+0

[固定寬度列與自舉中的容器流體]可能的副本(https://stackoverflow.com/questions/36060117/fixed-width-column-with-a-a-container-fluid-in-bootstrap) – ZimSystem

回答

0

像這樣的東西?

#sticky-sidebar { 
 
    position:fixed; 
 
    max-width: 20%; 
 
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/css/bootstrap.min.css" rel="stylesheet"/> 
 
<div class="container"> 
 
    <div class="row"> 
 
    <div class="col-xs-4"> 
 
     <div class="col-xs-12" id="sticky-sidebar"> 
 
     Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. 
 
     </div> 
 
    </div> 
 
    <div class="col-xs-8" id="main"> 
 
     Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. 
 
    </div> 
 
    </div> 
 
</div

+0

不是一個粘性的側欄,「固定和靈活的寬度」列。例如。左欄爲200px,右欄佔據剩餘容器寬度的100%。因此需要使用Flexbox。 – user1960364

+0

這不起作用。調整瀏覽器大小時,左列不保留其寬度。 – Mark

2

這是你在找什麼:

HTML代碼---- >>

<div class="main-container"> 
    <div class="left"> 
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. 
    </div> 
    <div class="right"> 
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. 
    </div> 
</div> 

CSS ------- >>

.main-container{ 
    display:flex; 
    flex-direction:row; 
} 

.left{ 

    min-width:200px; 
    max-width:200px; 
} 

Codepen鏈接。