

What's the difference between the alignment values of start, flex-start, and sel...
source link: https://csslayout.news/whats-the-difference-between-the-alignment-values-of-start-flex-start-and-self-start/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

When aligning items to the start and end of a line in flexbox, there are a number of values to choose from. In this post I'm going to explain the difference between some values which appear to do very similar things:
flex-start
andflex-end
start
andend
self-start
andself-end
The start
, end
, self-start
and self-end
values are available in Firefox, and in Chrome Canary. They are expected to ship in Chrome 93. For the demos to work you will need a supporting browser.
Some flexbox terminology
There are some terms that are useful in helping to understand alignment in flexbox. I'll be using them below, and they will help if you want to read more about this subject in the Box Alignment specification.
The alignment container
This is the parent of your flex items, therefore the element that has display: flex
added to it.
The alignment subject
This is a flex item, the thing that is being aligned.
The main axis
This is the direction of the flex-direction
property. If the value of this property is row
your main axis is row
.
The cross axis
This is the other direction from that set by flex-direction
. If flex-direction
is row
your cross axis is column
.
Main-start and main-end
The start and end of the main axis.
Cross-start and cross-end
The start and end of the cross axis.
Note that other than flex-start
and flex-end
, which are specific to flexbox, these values can be used in any formatting context that supports alignment, for example, CSS Grid Layout.
flex-start and flex-end compared to start and end
In the following example, there is a flex container (the alignment container), with two flex items (the alignment subjects) inside. The initial flex-direction
is row
.
Using the select boxes, try out the different values for justify-content
. With flex-direction: row
it appears that flex-start
and start
do the same thing, likewise for flex-end
and end
.
Change flex-direction
to row-reverse
however, and you can see the difference. When using row-reverse
the main-start and main-end have been switched. The main-start is now on the right, and main-end on the left. This has not changed the text direction, however, which still runs left to right.
Now try the various values of justify-content
. You will find that flex-end
moves the items to the left—the main-end of the flex container. Use end
and the items move to the right, this being the flow-relative end of the container.
Try the demo using direction: rtl
on the container to see how changing the text direction changes how these values work.
Therefore, if you want the item to align with the end as defined by flex-direction
, use flex-end
. To align it with the end of the alignment container, use end
.
self-start and self-end compared to start and end
In the previous example, you saw that start
and end
are flow relative, and relate to the writing mode and script direction. The self-start
and self-end
values are also flow-relative but they relate to the writing mode and direction of the alignment subject, in this case a flex item.
To see how this works, take a look at the following demo. There are three flex items in the container which has a flex-direction
of column
. The cross-axis is therefore along the row. The second item has direction: rtl
.
With align-items: start
, the items all line up on the left, as the container has a left to right direction. However, change that to align-items: self-start
, and item number two aligns to the end of the flex container—its flow relative start.
Therefore, if you want the item to respect the direction or writing mode of the alignment container, use start
and end
. To respect the writing mode or direction of the alignment subject, use self-start
and self-end
.
Sharing image by Debby Hudson on Unsplash.
Recommend
-
97
When people are new to JPA, Hibernate or EclipseLink, they are often confused about the difference between them and which one they should use in their project. If you're one of them, don't worry. It's a lot easier than it seems.
-
77
Constructor and Destructor are the special methods which makes our crucial tasks easier while programming. If you have ever worked in programming language like C++ then you must have encountered these two terms. Being met...
-
14
In JavaScript, you can pass by value and by reference. The main difference between the two is that passing by value happens when assigning primitives while passing by reference when assigning objects. Let’s discuss values and...
-
9
This article will teach you the difference between a primary key and foreign key. This article will also teach you why both of these keys are important when it comes to the ma...
-
7
Computer Science > Software Engineering [Submitted on 8 Feb 2022] Assessing the alignment between the information needs of developers and the docume...
-
5
Use the Query String to pass an array of selected values between Blazor PagesApril 28, 2022 · 5 minute read · Tags: blazorA common require...
-
4
Curve Flex by Twelve South: Between elegance and portability
-
5
Tanja Schaettler October 14, 2022 10 minute re...
-
10
The problem # Often, I come across a complex problem that I can’t solve myself. This is the purpose of libraries, so just import one and y...
-
7
The new Dynamic Axis Ranges feature in v2023.3 of Tableau enables you to change the chart axis start and end values based on parameters. Combined with parameter actions, this makes your dashboards more dynamic and reactive to user...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK