且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Flexbox 与 Twitter Bootstrap(或类似框架)

更新时间:2023-08-19 22:35:34

出于几个原因,flexbox 比 bootstrap 好得多:

For a couple of reasons, flexbox is much better than bootstrap:

  • Bootstrap 使用浮动来制作网格系统,许多人会说这不适用于网络,而 flex-box 则相反,通过对项目的大小和内容保持灵活性;与使用像素与使用 em/rem 的区别相同,或者仅使用边距和填充来控制 div,而从不设置预定义的大小.

  • Bootstrap uses floats to make the grid system, which many would say is not meant for the web, where flex-box does the opposite by staying flexible to the items' size and contents; same difference as using pixels vs em/rem, or like controlling your divs only using margins and padding and never setting a pre-defined size.

Bootstrap,因为它使用浮点数,每行后都需要clearfix,否则你会得到不同高度的未对齐的div.Flex-box 不会这样做,而是检查容器中最高的 div 并坚持其高度.

Bootstrap, because it uses floats, needs clearfix after each row, or you will get misaligned divs of different height. Flex-box doesn't do that and instead checks for the tallest div in the container and sticks to its height.

我会使用 bootstrap 而不是 flex-box 的唯一原因是缺乏浏览器支持(主要是 IE)(已经死了).有时即使 Chrome 和 Safari 使用相同的 webkit 引擎,您也会得到不同的行为.

The only reason I would go with bootstrap over flex-box is lack of browser support (IE mainly) (die already). And sometimes you get different behavior from Chrome and Safari even though both use the same webkit engine.

顺便说一句,如果您面临的唯一问题是等高的列,那么有很多解决方案:

BTW if the only problem you are facing is the equal height columns, there are quite a few solutions for that:

  • You can use display: table on the parent, an display: table-cell; on the child. See How to get same height in display:table-cell

您可以在每个 div 上使用绝对定位:
位置:绝对;顶部:0;底部:0;

You can use absolute positioning on each div:
position: absolute; top: 0; bottom: 0;

编辑 2:

还要检查 http://chriswrightdesign.com/experiments/flexbox-adventures/ &https://scotch.io/tutorials/a-visual-guide-to-css3-flexbox-properties 关于 flex-box 的工作原理.

Also check http://chriswrightdesign.com/experiments/flexbox-adventures/ & https://scotch.io/tutorials/a-visual-guide-to-css3-flexbox-properties on how flex-box works.

编辑 3:https://kyusuf.com/post/almost-complete-guide-to-flexbox-without-flexbox

编辑 4:https://caniuse.com/#feat=flexbox