Quantcast
Channel: Active questions tagged flexbox - Stack Overflow
Viewing all articles
Browse latest Browse all 1675

In CSS Flexbox, why are there no "justify-items" and "justify-self" properties?

$
0
0

Consider the main axis and cross axis of a flex container:

An illustration of the various directions and sizing terms as applied to a row flex containerSource: W3C

To align flex items along the main axis there is one property:

To align flex items along the cross axis there are three properties:

In the image above, the main axis is horizontal and the cross axis is vertical. These are the default directions of a flex container.

However, these directions can be easily interchanged with the flex-direction property.

/* main axis is horizontal, cross axis is vertical */flex-direction: row;flex-direction: row-reverse;/* main axis is vertical, cross axis is horizontal */    flex-direction: column;flex-direction: column-reverse;

(The cross axis is always perpendicular to the main axis.)

My point in describing how the axes' work is that there doesn't seem to be anything special about either direction. Main axis, cross axis, they're both equal in terms of importance and flex-direction makes it easy to switch back and forth.

So why does the cross axis get two additional alignment properties?

Why are align-content and align-items consolidated into one property for the main axis?

Why does the main axis not get a justify-self property?


Scenarios where these properties would be useful:

  • placing a flex item in the corner of the flex container
    #box3 { align-self: flex-end; justify-self: flex-end; }

  • making a group of flex items align-right (justify-content: flex-end) but have the first item align left (justify-self: flex-start)

Consider a header section with a group of nav items and a logo. With justify-self the logo could be aligned left while the nav items stay far right, and the whole thing adjusts smoothly ("flexes") to different screen sizes.

  • in a row of three flex items, affix the middle item to the center of the container (justify-content: center) and align the adjacent items to the container edges (justify-self: flex-start and justify-self: flex-end).

Note that values space-around and space-between onjustify-content property will not keep the middle item centered about the container if the adjacent items have different widths.

#container {  display: flex;  justify-content: space-between;  background-color: lightyellow;}.box {  height: 50px;  width: 75px;  background-color: springgreen;}.box1 {  width: 100px;}.box3 {  width: 200px;}#center {  text-align: center;  margin-bottom: 5px;}#center > span {  background-color: aqua;  padding: 2px;}
<div id="center"><span>TRUE CENTER</span></div><div id="container"><div class="box box1"></div><div class="box box2"></div><div class="box box3"></div></div><p>note that the middlebox will only be truly centered if adjacent boxes are equal width</p>

jsFiddle version


As of this writing, there is no mention of justify-self or justify-items in the flexbox spec.

However, in the CSS Box Alignment Module, which is the W3C's unfinished proposal to establish a common set of alignment properties for use across all box models, there is this:

enter image description here                                                                                                                                                   Source: W3C

You'll notice that justify-self and justify-items are being considered... but not for flexbox.


I'll end by reiterating the main question:

Why are there no "justify-items" and "justify-self" properties?


Viewing all articles
Browse latest Browse all 1675

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>