How to break out of 12 col grid with bootstrap 4 flexbox grid?

孤街醉人 提交于 2020-01-05 04:59:29

问题


When I heard bootstrap 4 was going to employ flexbox for a grid system I was really excited. I thought that this would deploy the fast and useful element sizing that flexbox is known for. However it seems that it just adds some (major) functionality to the current 12 col grid system.

Does Bootstrap 4 make it any easier to relate column widths in a non 12 col layout?

Like how flex boxes can be related to each other simply by specifying the horizontal space to divide using flex-item properties like flex-grow, flex-shrink and flex-basis.

[1:5][-----3:5-----][1:5]

This would be done with a simple flex:3; on the col2 item. But still seems impossible in bootstrap 4? Maybe I'm missing something?


回答1:


Bootstrap 4 has flexbox, and it's still based on a 12-unit grid, however there is also a new auto-layout grid which allows for any number of columns...

Auto-layout columns: http://codeply.com/go/JbGGN4Ok3A


Also, using SASS, you can change the number of grid columns using the $grid-columns variable. In your example, a 10-unit grid would work. Combine this with auto-layout and you can get:

[1:5][-----3:5-----][1:5]

SASS

  $enable-flex:true;
  $grid-columns: 10;
  $grid-gutter-width: 15px;

HTML

 <div class="row">
         <div class="col-xs">
              1:5
         </div>
         <div class="col-xs-6">
               3:5
         </div>
         <div class="col-xs">
               1:5
         </div>
 </div>

http://codeply.com/view/WG1jllYC2K

Note: You can also use the $grid-gutter-width variable to change the spacing between columns.

UPDATE

Bootstrap 4.0.0: https://www.codeply.com/go/6jTDGBnPIO


As of Bootstrap 4 (alpha 6) the auto-layout .col is now used for flex-grow so that you can create half-unit column layouts. The 2.5--7--2.5 layout is mathematically very close to your 1.5--3.5--1.5 (10-unit) so this may be another option instead of the custom SASS 10 unit grid. http://www.codeply.com/go/kBqRVNPE6E



来源:https://stackoverflow.com/questions/38799090/how-to-break-out-of-12-col-grid-with-bootstrap-4-flexbox-grid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!