4

I am confused. I have just discovered this CSS property: display:box; I do not understand what it brings to CSS that was not already possible with display: block, inline, inline-block.

Anyone can enlight me on this ? Thanks in advance.

0

4 Answers 4

10

It's part of the new flexbox module. From the working draft:

In the flexbox layout model, the children of a flexbox can be laid out in any direction, and can "flex" their sizes, either growing to fill unused space or shrinking to avoid overflowing the parent. Both horizontal and vertical alignment of the children can be easily manipulated. Nesting of these boxes (horizontal inside vertical, or vertical inside horizontal) can be used to build layouts in two dimensions.

It's still a draft specification, but worth playing with until it's fully implemented by browsers. It will probably allow us to get rid of floats in many cases!

Please note that display:box is already deprecated in favor of display:flexbox.

Last but not least: do not rely on w3schools!

Sign up to request clarification or add additional context in comments.

4 Comments

nothing wrong with w3schools. w3fools provides only opinion - no data.
@Pat When I posted this answer over an year ago, the site had a huge list of examples. I'm assuming w3schools has been working on the content, and the list was removed. Anyway, I still don't trust them. And thank you for the downvote.
"Anyway, I still don't trust them." - without data this is a not-very-helpful opinion. Since w3schools has the excellent "Try It" feature. I strongly disagree. "And thank you for the downvote." - always glad to help.
@Pat Just so you know what I was talking about back in 2012: web.archive.org/web/20120418014939/http://w3fools.com
3

You may find more info here.

Brief summary:

CSS 3 introduces a brand new box model in addition of the traditional box model from CSS 1 and 2. The flexible box model determines the way boxes are distributed inside other boxes and the way they share the available space.

This box model is similar to the one used by XUL (the user interface language used by Firefox). Some others languages use similar box models such as XAML or GladeXML.

Usually the flexible box model is exactly what you need if you want to create fluid layouts which adapt themselves to the size of the browser window or elastic layouts which adapt themselves to the font size.

...

By default, the traditional CSS box model distributes boxes vertically depending on the HTML flow. With the flexible box model, it’s possible to specify the order explicitly. You can even reverse it. To switch to the flexible box model, set the property display to the value box (or inline-box) on a box which has child boxes.

5 Comments

A downvote for posting a link to mozilla.org where an explanation of display:box is documented? I could have pasted the entire article in my post, but that would be redundant.
A downvote for posting only a link to mozilla.org. You couldn't even be bothered to explain what you're expecting me to go look at. But even aside from that, what happens when mozilla.org changes their links around tomorrow? Paraphrase here, at least.
As you wish... Summary posted.
You could at least change the words up. :) Oh well, though. Least there's something explained here now.
Hey now, at least your answer didn't get outright deleted by a mod as is often complained about on meta.
2

Take a look at the documentation from MDN:

The CSS box-orient property specifies whether an element lays out its contents horizontally or vertically.

For example, XUL box and hbox elements lay out their contents horizontally by default, but XUL vbox elements lay out their contents vertically by default.

HTML DOM elements lay out their contents along the inline-axis by default. This CSS property will only apply to HTML elements with a CSS display value of box or inline-box.

Comments

1

display:box allows:

  • Flexible distribution of boxes with box-orient, box-direction, box-ordinal-group... You can modify the normal distribution of boxes inside another box not only from vertical to horizontal (can be achieved by inline, inline-block or block with some float trick) but also in a reverse order (horizontal reverse order can be achieved by some float trick) and even in an explicit order.
  • Flexible sizing: the size of the boxes can be computed as the explicit size (using height, width, max-height, max-width...) or the size of the parent box and available space (with box-flex).
  • Handle the available space with box-align, box-pack, box-lines...

the new box model can do something the old model can't without additional javascript calculation, not much

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.