2016-11-08 14 views
6

enter image description hereLàm cách nào để tạo bố cục thanh bên cố định bằng Bootstrap 4?

Tôi đang cố gắng tạo bố cục như ảnh chụp màn hình bằng Bootstrap 4 nhưng tôi đang gặp một số vấn đề với việc cố định thanh bên và đạt được bố cục này cùng một lúc.

Đi với một ví dụ cơ bản:

<div class="container"> 
    <div class="row"> 
    <div class="col-m-4" id="sticky-sidebar"> 
     Sidebar 
    </div> 
    <div class="col-m-8" id="main"> 
     Main Area 
    </div> 
    </div> 
</div 

Nó có thể làm cho bố cục này nhưng mọi thứ trở nên khó khăn khi tôi tuyên bố:

.sidebar { 
position: fixed // or absolute 
} 

Khi tôi làm cho sidebar dính, các chính div bắt đầu xuất hiện phía sau thanh bên thay vì bên cạnh nó. Tất nhiên nó có thể tuyên bố một số lợi nhuận và đẩy nó trở lại vị trí ban đầu của nó nhưng nó làm cho mọi thứ phức tạp để đáp ứng.

Tôi cảm thấy như tôi đang thiếu một cái gì đó, tôi đọc tài liệu Bootstrap 4 nhưng tôi không thể tìm thấy một cách đơn giản để đạt được bố cục này.

Trả lời

4

giống như thế này?

#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

Nếu bạn thêm một số ipsum lorem nội dung sidebar của bạn, bạn có thể thấy rằng vấn đề ban đầu của tôi được tái tạo trong đoạn này. Bởi vì chúng tôi đang tuyên bố một vị trí cố định, thanh bên dừng việc tôn trọng hệ thống lưới. – cinnaroll45

+0

Tôi đã chỉnh sửa mã đã thêm 'chiều rộng tối đa: 20%' vào thanh bên – GvM

+0

Có, việc khai báo chiều rộng tối đa cho vùng chứa sẽ khắc phục sự cố. Cảm ơn! – cinnaroll45

-1

phiên bản của tôi:

div#dashmain { margin-left:150px; } 
div#dashside {position:fixed; width:150px; height:100%; } 
<div id="dashside"></div> 
<div id="dashmain">       
    <div class="container-fluid"> 
     <div class="row"> 
      <div class="col-md-12">Content</div> 
     </div>    
    </div>   
</div> 
Các vấn đề liên quan