Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flexbox: flex-start, self-start, and start; What's the difference?

I just noticed some values of the align-self property that I haven't seen before. What are start, end, self-start, and self-end and what are their differences from flex-start and flex-end?

I've been referring to the guide at CSS-Tricks often when I work with flexbox, but it doesn't mention these values. I read the documentation for align-self at MDN, but the one-line description of the values isn't enough for me to understand.

I thought I might be able to play around with the values to figure it out, but they all seem to do the same thing...

.container {    display: flex;    justify-content: center;    align-items: center;    background: papayawhip;    width: 400px;    height: 200px;    margin: 1rem auto;    box-shadow: 0px 0px 5px 1px rgba(0, 0, 0, 0.2);    border-radius: 0.5em;  }    .block {    color: white;    font-size: 3em;    font-family: sans-serif;    padding: 0.5rem;    margin: 0.5rem;    display: flex;    justify-content: center;    align-items: center;  }    .block-1 {    background: red;  }    .block-2 {    background: orange;  }    .block-3 {    background: gold;  }    .block-4 {    background: green;  }    .block-5 {    background: blue;  }    .block-2 {    align-self: flex-start;  }    .block-3 {    align-self: start;  }    .block-4 {    align-self: self-start;  }
<div class="container">    <div class="block block-1">1</div>    <div class="block block-2">2</div>    <div class="block block-3">3</div>    <div class="block block-4">4</div>    <div class="block block-5">5</div>  </div>
like image 357
Vince Avatar asked Jun 19 '18 01:06

Vince


People also ask

What is difference between Flex and flexbox?

Flexbox allows fine-tuning of alignments to ensure exact specification sharing. Flex Direction allows developers to align elements vertically or horizontally, which is used when developers create and reverse rows or columns.

What is the difference between Flex Start and baseline?

align-items: baseline When using align-items or align-self , the flex-start value will align flex items at the starting edge of the cross-axis of the flex container. The baseline value will align flex items along their content's baseline. The line upon which most letters "sit" and below which descenders extend.

What is Flex Start and flex-end?

flex-start : lines packed to the start of the container. flex-end : lines packed to the end of the container. center : lines packed to the center of the container. space-between : lines evenly distributed; the first line is at the start of the container while the last one is at the end.

What is Flex start?

Flex start classes allow you to begin your course after the semester start date. They are shorter than the typical 16-week class and usually last between eight to 14 weeks.


1 Answers

The values flex-end and flex-start (among others) were created for use with flex layout.

However, the W3C has been developing the Box Alignment Module, which establishes a common set of alignment properties and values for use across multiple box models, including flex, grid, table and block.

So what you're seeing are the newer values that will eventually replace the existing layout-specific values.

Here's how it's described in the flexbox specification:

§ 1.2. Module interactions

The CSS Box Alignment Module extends and supercedes the definitions of the alignment properties (justify-content, align-items, align-self, align-content) introduced here.

There's similar language in the Grid specification. Here's an example:

§ 10.1. Gutters: the row-gap, column-gap, and gap properties

The row-gap and column-gap properties (and their gap shorthand), when specified on a grid container, define the gutters between grid rows and grid columns. Their syntax is defined in CSS Box Alignment 3 §8 Gaps Between Boxes.

The original properties – grid-row-gap, grid-column-gap and grid-gap – didn't last long. Although, for the sake of backward compatibility, I'm sure they're still respected.

like image 79
Michael Benjamin Avatar answered Sep 18 '22 14:09

Michael Benjamin