
How To Align Matters In CSS
Rachel Andrew 2019-03-28T12:30:41+01:00
2019-04-09T21:06:48+00:00
However, you do need to have the ability to align portion of the group of items in a way that is different or one item. A common pattern could be a split navigation bar with one thing being separated out from the group. In that situation, the specification informs the use of automobile margins.
The justify-content
and align-content
properties in Grid and Flexbox are about dispersing extra distance . So that the thing is that you’ve got additional space.
Grid Layout implements all the properties for both axes since we have two axes. We create tracks (which may leave extra space in the grid in dimension,) and so we can distribute that space using align-content
or justify-content
. We also have Grid Areas, and the part in that region may not take up the full area of the region, thus we are able to use align-self
or justify-self
to transfer the content around the area (or align-items
, justify-items
to modify the alignment of all items).
you can see that inline is inline — no matter which writing mode you are 28, once again, I have two grid layout examples.
Remember that the line-height
house will change the size of this line-box and so may change your alignment. The following example uses a large line-height worth of 150px, and I’ve aligned the image to top
. The picture is aligned to the line box’s peak rather than the top of the text, ensure it is less than the size of the image and the picture and text will line up on peak of the text or eliminate that line-height.
The Two Types Of Alignment
In grid, I will use the things to be moved by all four properties around . When playing with alignment, that the Firefox DevTools Grid Inspector is going to be helpful. You can see the Region inside which the material has been moved, with the grid lines :
See the Pen Cross axis recovery at Flexbox by Rachel Andrew.
- You have the spare room in the grid or bend container (after the items or paths have been laid out).
- In addition you have the item itself inside the grid place you put it in, or on the cross axis within the flex container.
Every line of content is treated as a box when we have any text and inline elements on a page. The land text-align
will align that articles on the webpage, by way of instance, if you want your text centered, or justified. However, if you have an icon or text of different dimensions, you may choose to align items inside that line box for instance, contrary to other items.
In my example below, I have a bend plus a grid container, and am using align-items
and align-self
in Flexbox to move the items up and down from each other on the cross axis. If you use Firefox, then inspect the element using the Firefox Flexbox Inspector, you can observe the way the things are being transferred inside of that and the size of this flex container.
See the Pen Grid Block Axis Alignment by Rachel Andrew.
If I now add more content to my items so they become bigger and there is no longer any extra distance, then justify-content
does nothing — simply because there’s absolutely no space to disperse.
Here is a Flex example: I’ve set flex-direction: row
and I have three items. They don’t occupy all the space in the bend container, so that I have spare space on the principal axis, the initial value for justify-content
is flex-start
and so my items all line up at the start and the excess distance is at the end. I am using the Firefox Flex Inspector to underline the space.
There is not any reason not to utilize even, or Flexbox Grid for tiny layout jobs. They are not just for big chunks of layout. Try the different things available to you, and see what works.
Below, I have a grid illustration and a flex example. Both have a container that is larger than required to exhibit the flex items or grid tracks, so I will utilize align-content
and justify-content
to disperse distance.
As we can do this axis alternating, the most important factor in Flexbox is asking,”Which axis is my main axis?” Once you know that, then for alignment (when on your main axis) you just use justify-content
. Whether your axis is column or row, it doesn’t matter. You control space involving the bend items with justify-content
.
For Grid Layout, you need to know if you’re aligning in the Inline or Block Direction. The Block management is the direction blocks lay on your page (in your composing manner ), i.e. for English that is vertically. The Inline management is the direction in which paragraphs run (so for English that’s left to right horizontally).
These properties manage the actual flex or grid item, i.e. transferring the material around within the Grid Area or flex line.
I showed a set of properties to you above, and also the alignment properties can be thought of as two groups. Those that deal with supply of spare space.
We’ve got a choice of approaches to align things today, and it isn’t always an obvious decision which to use. However, knowing what’s available means which you can attempt a few tactics if you come across a alignment issue.
Box Alignment
The vertical-align
property is useful if you are organizing any inline element. This includes elements with screen: inline-block
. The content of table cells may also be matched with the vertical-align
property.
Add a height to the container and — provided that that is more than is needed to display the things — you have additional space and therefore justify-content
will work on your own column.
- Grid Layout
You get the two possessions as you’re able to alter the item on the block and inline as we have a specified Grid Area in which it sits. - Flex Layout
You can just align to the cross axis as the primary axis is controlled by space distribution alone. If your items are a row, you may usealign-self
to change them up and down within the flex line, aligning them from each other.
Flexbox is a little trickier because of the simple fact that we now have a main axis that could be changed to row
or column
. So, let’s first think about that main axis. It is set with all the flex-direction
property. The initial (or default) value of this home is row
that will lay the bend items out as a row at the composing mode now in use — this is the reason when working in English, we wind up with items laid out when we create a bend container. After that you can change the most important axis to flex-direction: pillar
and the objects will be laid out as a column which means they are laid out in the block direction for this composing manner.
To align matters in the Block Direction, you may use the properties that start with align-
. You use align-content
to distribute space between grid monitors, if there’s free space from the grid , and align-items
or align-self
to move an item around inside the grid area it has been put in.
I have a review of the fundamentals of alignment, to wrap up. If you remember these few guidelines, you should Have the Ability to align most items with CSS:
Flexbox does not have tracks in the manner that Grid design does. On the main axis with is the supply of space between the products. There is no idea of a path into. So there is no area in which to move around the thing in, created. This is why there isn’t any justify-self
land on the primary axes in Flexbox.
The vertical-align
land has no impact on grid or flex products, and therefore if used as part of a fallback strategy, will cease to use the minute the parent element has been become a grid or bend Container. For example, in the next pen, I’ve got a set of items laid out with display: inline-block
and this means I get the capability to align the things even when the browser does not have Flexbox:
Individuals are very keen to know what the correct or wrong way is. In reality, there frequently is no right or wrong; a small difference in your pattern might indicate that the difference between Flexbox working best, where otherwise you would utilize vertical-align
.
If I change flex-direction to space-between
, that extra space is currently distributed between the items:
justify-content
align-content
justify-self
align-self
justify-items
align-items
.container
The Box Alignment Specification deals with how we align everything else. The details the alignment properties that are following:
The below case has two grid layouts. One has writing-mode: horizontal-tb
(that is the default option for English) and another writing-mode: vertical-rl
. This is the difference between these. You can see that the alignment properties that I have implemented work in exactly the exact same fashion on the block axis in the two manners.
One of the things which I think is often overlooked is how useful Flexbox is for doing miniature layout jobs, where you might think that using vertical-align
is your thing to do. I often utilize Flexbox to get neat alignment of small patterns aligning an icon next baseline aligning two things or creating form fields and buttons line up. If you're struggling to have some thing to line up well with vertical-align
, then perhaps try doing the task with Flexbox. Bear in mind that you may also create an inline bend container if you would like with display: inline-flex
.
To Learn More about alignment, see these resources:
The fact that vertical-align
operates on table cells is the reason that the trick to vertically center a product using screen: table-cell
functions .
Wrapping Up
As being a part of perhaps, or even the Flexbox Specification Grid you may think of these properties. These properties' history is that they exist at the Level 1 specification, and originated as part of Flexbox; when it became apparent that they had been more generally 42, however, they had been moved in their own specification. We now also use them in Grid Layout, although current browser support means that you won't have the ability to use them just yet, and they're specified for design methods too.
The properties which finish in -content
are about distance supply, so once you choose to use align-content
or justify-content
you are distributing available space between grid tracks or flex products. Themselves don't change the size of the flex or grid things; they move them around because they alter where the spare distance moves.
Display: bend;
align-items: center;
justify-content: middle;
- Are you aligning an inline element? If that’s the case, you have to use
text-align
,vertical-align
, andline-height
. - Can you have an item or items that you want to align at the middle of the page or container? If that’s the case, make the container a bend container then set
align-items: center
andjustify-content: centre
. - For Grid Layouts, the properties that begin with
align-
work from the Block management; those that start withwarrant -
work from the inline direction. - For Flex Layouts, the attributes that begin with
align-
work on the Cross Axis; those which start withwarrant -
operate on the primary axis. They’ll do nothing, if you don’t have any excess space in your flex or grid . - If you think you need
justify-self
at Flexbox, then utilizing an auto margin will probably give you the pattern you’re after. - You can utilize Grid and Flexbox along with the alignment properties for miniature layout jobs as well as main components — experimentation!
Play around with the values from the CodePen demo to see how content can be shifted by you around in every layout method:
See the Pen Grid Inline Alignment by Rachel Andrew.
Now that we do have better methods to align boxes in CSS (since we’ll look at in the next section), we don’t need to use the vertical-align
and text-align
possessions in areas other than the text and inline components for which they have been created. They are still valid to use in these inline and text formats, so remember if you are trying to align something inline, it’s these properties and not the Box Alignment ones which you want to reach for.
From the example below, I’ve got some text with a inline picture that is larger. I’m using vertical-align: middle
on the image to align with the text into the middle of the picture.
You have two things that are possible to align, when aligning grid and flex items:
A common question I’m asked is the reason justify-content
is not working when flex-direction
is column
. This is because there is not any room to distribute. If you choose the above example and make it flex-direction: column
, the things will exhibit as a pillar, but there will be no extra space below the items as there is when you do flex-direction: row
. That is because when you make a Flex Container with screen: flex
you’ve got a block flat flex container; this will take up all potential space in the inline direction. In the block management, so no excess space, matters do not stretch in CSS.
I will have a look at the various procedures. Rather than providing each with a thorough guide, I’ll clarify a few of the points individuals have and purpose to comprehensive references for the properties and values. Just like much of CSS, it is possible to go a very long way by knowing the fundamental things about the way the methods act, and then need somewhere to go look up the finer details in terms of how you attain the precise design you would like.
One of the issues with people remembering the properties in Grid and Flexbox, is that nobody can remember if to align or to warrant. Which direction is which?
From the example below, we are doing both using a flex container displayed as a row and a column:
It turns out that line-height
and indeed the magnitude of text is fairly complex, and I am not going to head down the rabbit hole in this report. If you are trying to precisely align inline components and want to actually understand what’s going on, I suggest reading”Deep Dive CSS: Font Metrics, line-height
And vertical-align
.”
Dealing With Spare Space: align-content
And justify-content
In the future, we may even have the ability to dispense with display: flex
, once the Box Alignment possessions are implemented for Block Layout. At the moment, however, making the parent of the thing you want centering there is a flex container the best way to acquire alignment horizontally and vertically.
In this pen, I’ve treated the inline-block
as a fallback for Flex layout. The alignment possessions no longer use, and that I can add align-items
to align with the items in Flexbox. You can tell that the Flexbox technique is in play since the difference between items that you will get when utilizing display: inline-block
is gone.
To align matters in the inline direction, use the properties that begin with warrant -
. Utilize justify-content
to distribute space between grid paths, and justify-items
or justify-self
to align objects inside their grid area in the inline direction.
See the Pen inline-flex example from Rachel Andrew.
Therefore, next time someone on the Internet tells you that vertical orientation is the toughest part of CSS, you can tell them (which fits to a tweet):
On the cross axis, you can use align-items
that will align the objects within the bend container or bend line at a multi-line flex container. In case you have a multi-line container using flex-wrap: wrapping
and have room in that container, then you may use align-content
to distribute the space on the cross axis.
-
See the Pen justify-content and align-content by Rachel Andrew.
- CSS Box Alignment (MDN web docs)
An auto margin will take up all of the space in the direction it’s applied, which is precisely why we can center a block (such as our principal page layout) with a left and right margin of auto. Having an automobile margin on either side, each perimeter tries to carry up all the space and so pushes the block into the center. With all our row of flex items, we can add
margin-left: automobile
to the item we need the split to take place on, and as long as there is available space in the flex container, you get a split. This plays because as soon as there isn’t any available space, the things behave as regular flex items do.
When Can I Use The vertical-align
Property?
See the Pen Alignment with auto margins by Rachel Andrew.
As being a part of this Flexbox Specification, or even perhaps Grid you might think of those properties. The history of the properties is that they still exist at the Level 1 specification, and originated within Flexbox; when it became apparent that they were generally 42, however, they had been moved into their own specification. They are now used by us in Grid Layout, although current browser support ensures you won’t be able to use them just yet, and they are specified for other design methods too.
Sometimes you do need to be able to align one item or part of the group of items in a manner that is different. A pattern would be a split navigation bar with one item. In that situation, the specification informs the use of automobile margins.
Bear in mind that the line-height
property will alter the size of the line-box and so may change your alignment. The following example uses a sizable line-height worth of 150px, also I have aligned the image to top
. The picture is aligned to the peak of the line box and not the cover of the text, eliminate that line-height or ensure it is less than the dimensions of the image and the image and text will line up on peak of the text.
An automobile margin will take up all of the space in the direction it’s implemented, and that’s why we can center a block (for instance, our main page layout) using a right and left margin of automobile. With an auto margin on either side, each margin attempts to carry up all the space and pushes the block into the middle. With all our row of flex items, we can add margin-left: automobile
to the thing we want the split to take place on, and so long as there is available space in the flex container, you get a split. This plays as flex things do, since soon as there isn’t any space that is available, the items behave.
In the future, we may even have the ability to dispense with screen: flex
, after the Box Alignment properties are implemented for Block Layout. Right now, however, which makes the parent of this thing you need centering there is a bend container the way to acquire alignment horizontally and vertically.
I have a fast summary of the basics of alignment to wrap up. If you remember these few guidelines, you should Have the Ability to align things with CSS:
(il)
Watch the Pen inline-flex illustration by Rachel Andrew.
In this pen, I’ve handled the inline-block
as a fallback for Flex design. The alignment possessions no longer apply, and that I can add align-items
to align with the items in Flexbox. You can tell that the Flexbox technique is in play because the difference between items that you will get when utilizing screen: inline-block
is gone.
We then have align-self
and justify-self
as applied to person flex or grid things; you might also utilize align-items
and justify-items
on the container to place all the properties at once. These properties deal with the actual flex or grid item, i.e. transferring the material around inside the Grid Area or bend line.
The Two Types Of Alignment
Wrapping Up
Dealing With Spare Space: align-content
And justify-content
On the cross axis, you may use align-items
which will align the items within the bend container or bend line at a multi-line flex container. In case you’ve got a multi-line container using flex-wrap: wrap
and have space inside that container, you can use align-content
to disperse the distance on the cross axis.
Watch the Pen Cross axis recovery at Flexbox by Rachel Andrew.
If I change flex-direction to .container So, next time someone Online informs you that vertical orientation is the hardest part of CSS, you can tell them (which even fits to a tweet):
space-between
, that extra space is now distributed between these items:
- You've got the spare room in the grid or bend container (once the things or paths are laid outside ).
- You also have the item itself inside the grid place you placed it in, or on the cross axis inside the bend container.
The below case has two grid layouts. One has writing-mode: horizontal-tb
(that is the default option for English) and another writing-mode: vertical-rl
. This is the difference between these. It is possible to see that the alignment properties that I have implemented work in precisely the exact same way on the cube axis in the two manners.
These properties manage the true flex or grid thing, i.e. moving the material around inside the Grid Area or bend line.
We have better methods to align boxes in CSS (as we'll look at in the next section)we do not have to employ the vertical-align
and text-align
properties in areas other than the text and inline elements for which they have been designed. But they are still valid to use in those inline and text formats, and so recall it's not and these properties the Box Alignment ones if you are attempting to align something inline that you need to achieve for.
On the cross axis, you can use align-items
which will align the objects within the flex container or flex line at a multi-line flex container. If you've got a multi-line container using flex-wrap: wrapping
and have room inside that container, then you can use align-content
to disperse the distance on the cross axis.
There is no reason to not use Flexbox, or perhaps Grid for layout jobs. They are not only for big chunks of layout. Try out the things available to you, and see what works.
See the Pen Cross axis alignment in Flexbox by Rachel Andrew.
When we have other inline elements and any text on a page, every line of content is handled as a line box. The property text-align
will align that content on the webpage, for example, if you would like your text centered, or justified. Sometimes if you have an icon displayed alongside text, or text of various dimensions, you may choose to align items inside online box for instance.
See the Pen inline-flex illustration by Rachel Andrew.
Here's a Flex example: I have set flex-direction: row
and I have three things. They don't occupy all the space from the bend container, so I have spare space on the main axis, the initial value for justify-content
is flex-start
so my items all line up at the beginning and the extra distance is in the end. I'm using the Firefox Flex Inspector to underline the space.
Later on, we may even be able to dispense with screen: flex
, once the Box Alignment properties are employed for Block Layout. At the moment, however, making the parent of this thing you need centering a bend container is the way and vertically.
To align matters in the inline direction, use the properties that begin with justify-
. Use justify-content
to disperse space between grid tracks, and justify-items
or justify-self
to align objects within their grid space in the inline direction.
Display: flex;
align-items: center;
justify-content: center;
You have two things that are possible to align when aligning grid and flex Products:
The vertical-align
property is beneficial if you are organizing any inline element. This includes elements with display: inline-block
. The content of table cells may also be aligned with the vertical-align
property.
People are often very keen to know what the right or wrong means is. In fact, there frequently is no right or wrong; a little gap in your routine may mean that the difference between Flexbox working finest, where otherwise you would utilize vertical-align
.
The attributes that finish in -articles
are about space distribution, so once you choose to utilize align-content
or justify-content
you are distributing available space between grid tracks or bend products. They don’t alter the size of the flex or grid items ; they move them around since they change where the distance goes.
Add a elevation into the container and — provided that that is more than is needed to display the items — you’ve got extra space and therefore justify-content
will work on your own column.
In grid, I can use all four properties to move around the items inside their grid space. When playing with alignment, the Firefox DevTools Grid Inspector is going to be useful. You can see where the material has been transferred, the Region Together with the grid lines :
It ends up that line-height
and indeed the magnitude of text is fairly complex, and I am not going to head down the rabbit hole within this report. If you’re attempting to precisely align inline components and wish to really understand what’s going on, I suggest reading”Deep Dive CSS: Font Metrics, line-height
And vertical-align
.”
Play around with the values in the CodePen demonstration to see how content can be shifted by you around in every layout method:
An automobile margin will take up all the space from the direction it is applied, and that’s why we can center a block (such as our principal page layout) using a right and left margin of auto. Having an automobile margin on both sides, each margin tries to carry up of the distance and pushes the block to the middle. Together with all our row of flex items, we can add margin-left: automobile
to the thing we need the split to take place on, and as long as there is available space in the flex container, you get a split. This plays as flex items do since soon as there is no available space, the items behave.
As being a part of maybe, or the Flexbox Specification Grid you may already think of these properties. The history of the properties is that they originated within Flexbox, and exist in the Level 1 specification; when it became evident that they had been generally helpful however, they had been transferred into their specification. We also use them in Grid Layout, and they’re specified for additional layout methods also, although present browser service means that you won’t have the ability to use them just yet.
Below, I’ve a flex case and a grid example. Both possess a container that is larger than required to exhibit the flex items or grid tracks, so I can utilize align-content
and justify-content
to disperse distance.
The vertical-align
land has no effect on grid or flex products, and therefore if used as part of a fallback plan, will cease to apply the minute the parent component is become a grid or bend Container. By Way of Example, in another pen, I’ve got a set of items laid out using screen: inline-block
and this implies I possess the ability to align the items even when the browser does not have Flexbox:
Flexbox doesn’t have paths in the way that Grid layout does. On the axis, all we have to play is the distribution of distance between the items. There’s no idea of a track into. So there’s absolutely no area in which to move around the item in, created. That is why there is no justify-self
land on the main axes in Flexbox.
- Grid Layout
You get the two properties because you’re able to shift the item on the block and inline as we have a defined Grid Area where it sits. - Flex Layout
You can just align to the cross axis as the main axis is controlled by distance distribution alone. If your items are a row, you can usealign-self
to change them up and down inside the bend line, then aligning them against each other.
I will have a peek at the alignment procedures that are various. Rather than providing every with a comprehensive guide, I will explain a few of the points people have and point to references for the properties and properties. As with much of CSS, you can go a long way by understanding the fundamental things about the way the methods act, and then need somewhere to go look up the finer details with regard to how you attain the precise design you would like.
As we could do this axis alternating, the most important element in Flexbox is asking,”Which axis is my main axis” Once you understand that, then for alignment (when on your main axis) you just utilize justify-content
. Whether your main axis is column or row it doesn’t matter. You control distance between the flex items with justify-content
.
Because we constantly have two axes to deal with in Grid Layout grid Layout implements each the properties for both axes. We create tracks (which may leave extra space in the grid in dimension,) and so we can distribute that distance using align-content
or justify-content
. We also have Grid Areas, and the element in that area might not occupy the entire space of the region, thus we are able to utilize align-self
or justify-self
to move the material around the region (or even align-items
, justify-items
to modify the alignment of items).
The Two Kinds of Alignment
To align things in the Block Direction, you may use the properties which begin with align-
. You utilize align-content
to disperse space between grid monitors, if there’s free space in the grid , and align-items
or align-self
to maneuver a product around inside the grid area it has been placed in.
.container
If I add more content to my things in order that they become bigger and there isn't any longer any additional distance, then justify-content
does nothing -- simply because there's absolutely not any space to distribute.
We have an entire selection of ways to align things now, and it is an obvious decision which to use. But, knowing what is available means if you happen across a particular alignment problem which a couple of tactics can always try.
Watch the Pen Grid Block Axis Alignment by Rachel Andrew.
Watch the Pen inline-block flex fallback by Rachel Andrew.
Why Is There No justify-self
In Flexbox?
One of the things I think is often overlooked is how useful Flexbox is for performing miniature layout jobs, where you may think that using vertical-align
is your thing to do. I frequently use Flexbox to acquire neat alignment of small patterns aligning a icon next to text, baseline aligning two things using different font sizes, or creating buttons and form fields line up. If you're struggling to have some thing to line up well with vertical-align
, then maybe try out doing the task with Flexbox. Remember you may also produce an inline bend container in case you would like with display: inline-flex
.
Sometimes you really do want to have the ability to align part of the group of things in a different way or one item. A common pattern would be a split navigation bar with one thing being separated out from the group. In that circumstance, the specification advises the use of automobile margins.
To Learn More about alignment, see these sources:
In this next pen, I have handled the inline-block
for a fallback for Flex design. The alignment possessions no longer apply, and that I can add align-items
to align the items in Flexbox. You can tell that the Flexbox technique is in play because the difference between things that you will get when using screen: inline-block
is gone.
I showed you a set of properties above, and also the alignment properties can be considered as two classes. Those which deal with supply of space.
Remember that the line-height
house will alter the size of the line-box and so may change your alignment. The next example uses a large line-height worth of 150px, also I have aligned the picture to top
. The picture is aligned to the peak of the line box and not the top of the text, then eliminate that line-height or make it less than the size of the image and the picture and text will line up on top of the text.
In my example below, I have a flex and a grid container, and am using align-items
and align-self
in Flexbox to move the items up and down from each other on the cross liner. If you inspect the element using the Firefox Flexbox Inspector, then use Firefox, you can see the size of the flex container and the way the items are being moved inside of that.
- Are you aligning an inline element?
- Do you have an item or items that you need to align at the center of the page or container? If so, make the container a bend container then set
align-items: centre
andjustify-content: centre
. - For Grid Layouts, the properties that start with
align-
operate in the Block direction; those which begin withwarrant -
work in the inline direction. - For Flex Layouts, the properties that start with
align-
operate on the Cross Axis; people which begin withwarrant -
operate on the main axis. - The
justify-content
andalign-content
properties spread additional space. They will do nothing, if you have no extra space in grid or your bend. - If you think you require
justify-self
at Flexbox, then using an auto margin will probably give you the pattern you're after. - You can utilize Grid and Flexbox alongside the alignment properties for tiny layout jobs in addition to main components -- experiment!
One of those mentioned problems with people recalling the alignment properties in Flexbox and Grid, is that no one can recall to justify or if to align. Which direction is which?
When justify-content
Or align-content
Don't Work
I have two grid layout examples so that you can observe that inline is always inline -- no matter which composing mode you're currently using.
From the case below, we are doing both with a flex container displayed as a column and a row:
See the Pen justify-self, align-self, justify-items, align-items from Rachel Andrew.
The justify-content
and align-content
possessions in Grid and Flexbox are about distributing extra space. Therefore the thing is that you have additional space.
The simple fact that vertical-align
operates on table cells is the reason that the trick into vertically center a product using display: table-cell
functions .
In the example below, I've got some text with a inline image that is larger. I'm using vertical-align: centre
on the image to align with the text to the middle of the picture.
See the Pen Vertical Alignment example by Rachel Andrew.
When Can I Use The vertical-align
Real Estate?
Flexbox And Micro-Components
A frequent question I'm asked is the reason justify-content
is not functioning when flex-direction
is column
. This is because there is not any room. If you choose the above case and make it flex-direction: pillar
, the items will display as a pillar, but there'll be no extra space beneath the items because there is if you do flex-direction: row
. This is because when you create a Flex Container using screen: flex
you have a block level flex container; this is going to take up all potential space from the inline direction. In CSS, matters don't stretch in the block direction, so no extra space.
I've a summary of the fundamentals of alignment to wrap up. If you remember these rules, you should Have the Ability to align most things with CSS: Flexbox is somewhat trickier due to the simple fact that we have a main axis which can be changed to
The Box Alignment Specification deals with how we align everything else. The specification details the next alignment properties:row
or column
. Thus, let's first consider that most important axis. It is set using all the flex-direction
property. The first (or default) value of this home is row
which will lay the flex out items as a row in the writing mode currently in use -- this is why when working in English, we wind up with things laid out horizontally when we create a bend container. After that you can change the main axis to flex-direction: column
and the items will be laid out as a pillar which means they're laid out in the block direction for this writing manner.
For Grid Layout, whether you are aligning in the Block or Inline Direction you will need to learn. The Block management is the direction blocks lay on your own page (in your composing mode), i.e. for English that is vertically. The Inline direction is the direction in which sentences run (so for English that is left to right horizontally).