flexbox vs tables, why do we need flexbox?

前端 未结 3 1571
谎友^
谎友^ 2020-12-06 09:21

Can anyone please enlighten me on how the new Flexbox layout model is any better than current tables way? (display:table and all those are includedin my

相关标签:
3条回答
  • 2020-12-06 09:53

    There are three distinctions I can think of between using flexbox and using table display values or floats to layout a page:

    1. Being able to re-order elements irrespective of the HTML source order, while keeping elements in the normal flow - you can do this by specifying an integer value with the order property.
    2. It requires less typing than traditional float layouts (you don't need all of the pseudo-elements for clearing purposes) and is more semantic, while using floats or tables for layouts obviously isn't.
    3. The ability for flex-items to grow and shrink to fill horizontal and vertical space based on an ancestor elements' dimensions - by using the flex-grow and flex-shrink properties.

    The problem (as you've pointed out) is that support is still pretty bad; In fact Firefox is still implementing an older version of the flexbox module, so you have to account for minor discrepancies in syntax and behavior, depending on which browser you're using. It has been said quite a bit, though, that it is the future for layouts, especially for complex web apps that are popping up more often. It's worth learning if you're okay with making an inevitably wise investment - at the cost of not really being useable right now.

    I also suggest you take a look at this smashing magazine article for a friendly introduction to flexbox (it's fairly recently written)

    0 讨论(0)
  • 2020-12-06 09:59

    Simply put, it's something that'll be beneficial in a few years. Like many advanced css techniques, HTML5, etc., a few people will adopt them with painful fallbacks and shims/shivs for the next couple of years.

    When browsers support it in the future, we'll have a party and all hate on the 'old' browsers that don't support them :).

    0 讨论(0)
  • 2020-12-06 10:13

    The Flexbox model is more powerful than display table. Flexbox supports layouts for right to left languages for example. And yes indeed, flexbox is a bit complex and that's an entry barrier. Float and clearfix layouts are a (clever) hack, somehow in the same way table layouts are a hack, flexbox is meant for layout.

    The browser support is getting better lately, some say we should use it now. Bootstrap 3 does however not make use of flexbox, but i can imagine that the next version will.

    0 讨论(0)
提交回复
热议问题