align items to the right using flexbox [duplicate] - css

This question already has answers here:
In CSS Flexbox, why are there no "justify-items" and "justify-self" properties?
(6 answers)
Closed 2 years ago.
how to align a flex item to the right?
.row {
display: flex;
text-align: right; //nothing happens
}
<div className="row">
<div className="col">content</div>
</div>
the output of this is something like
| content |
and I´m looking for
| content |

Aligning items in flex needs to be handled using justify-content or align-items
You need to use justify-content in your code:
.row {
display: flex;
justify-content: flex-end;
}
When you use display:flex for an element it has a default flex-direction with value of row. it means your inner elements will be placed in a row. This direction(row) is your main direction. justify-content will specify the location of your items in their main direction.
The value of justify-content can be flex-start, flex-end, etc. You need to set it to flex-end which in your situation means right side.
I highly recommend you to read the below link for more information:
justify-content:
This defines the alignment along the main axis. It helps distribute extra free space leftover when either all the flex items on a line are inflexible, or are flexible but have reached their maximum size. It also exerts some control over the alignment of items when they overflow the line. A Complete Guide to Flexbox

.row {
display: flex;
flex-direction: row;
justify-content: flex-end;
}
First, you need to specify the direction of items (flex-direction) as row (horizontally) or column (vertically).
Then, if direction is row, align items using justify-content property with flex-end value. This will align items from the right to left (from the end of row to the start) / (oX axis)
If direction is column, align items using align-items property which have almost same values as justify-content, but is configured for vertically align (oY axis)
This post can help.

.row {
display: flex;
justify-content: flex-end;
}

Related

how to center section in weblayout for mobile?

I have a problem with section 'descr'.
When I open PC window, all content positions in center.
When I open mobile format, first section 'container' is ok (in center), but 'descr'
on the left side.
Why it could be?
'main' - is flex, and justify-content:center.
Also I added width:100% for 'main', but nothing changes
When flex-direction: column, justify content and align items are changing directions. So, you must use align-items: center; to set them on the center, because flex-direction is set to column.
You must add align-items: center not justify-content: center, because when you add flex-direction to column you reverse things.
.main {
width: 100%;
display: flex;
align-items: center;
flex-direction: column;
}
The main axis is defined by flex-direction, which has four possible values:
row
row-reverse
column
column-reverse
Should you choose row or row-reverse, your main axis will run along the row in the inline direction.
If flex-direction is set to row the main axis runs along the row in the inline direction.
Choose column or column-reverse and your main axis will run from the top of the page to the bottom — in the block direction.
If flex-direction is set to column the main axis runs in the block direction.
Therefore, by using flex-direction: column; you are saying that your main axis is the vertical axis. This means that justify-content: center; will align your items vertically, not horizontally. So, to align them horizontally, you must use align-items: center; to align the items along the cross axis.

Are there any significant differences (performance or otherwise) between using text-align versus flexbox's align-items to align text? [duplicate]

This question already has answers here:
What do "flex" and "justify-content" achieve that "text-align" doesn't?
(3 answers)
Closed 1 year ago.
I'm aware of the differences between the two. I'm concerned with what is best practice and if there are any performance or a11y implications with using one or the other. Example usages of the these would be:
text-align: left;
or
align-items: flex-start;
In this hypothetical scenario, I'm just working with text positioning.
If your container is flex-direction: row; adding align-items: flex-start; will move the text to the top of the container as align-items defines how flex-items are aligned on the cross axis. You would probably want to use justify-content: flex-start; in this scenario as that would align the text to the left, or start of the container. If you're like me and tend to put a text-align:center on the <body> it can be nice to use justify-content: flex-start (and align-items:center usually) as flexbox is just an awesome, powerful tool that you can use with limited code and you don't have to manually add a text-align property to every piece of code you want to be aligned differently than center.

CSS Flexbox align-items and justify-content [duplicate]

This question already has answers here:
In CSS Flexbox, why are there no "justify-items" and "justify-self" properties?
(6 answers)
Flexbox: center horizontally and vertically
(14 answers)
Closed 2 years ago.
For CSS Flexbox layouts, I have been given to understand that we have align-items property to align our item on the cross axis, while we use justify-content to align the item on the main axis.
Now does the above statement applicable only with the default flex-direction i.e. row
Does it change when we use flex-direction as column.
So essentially, I am confused with how the behavior of align-items and justify-content when we have flex-direction as column ?
Example
On following link
https://jsbin.com/wakagup/edit?html,output
.box {
display: flex;
flex-direction: column;
align-items: flex-start;
justify-content: flex-start;
}
If we change align-items from flex-start to flex-end, the divs seem to move horizontally rather than vertically which is what is confusing me.
Also, the divs move differently when we remove flex-direction: column; and try different values for the align-items/justify-content
When the direction is inverted the axis inverts thus the opposite behavior.
The flex-direction CSS property sets how flex items are placed in the
flex container defining the main axis and the direction (normal or
reversed). - MDN

Forcing alignment of div to bottom right of page using flex

We're using flexbox in our Angular 2 app but I'm running into an issue where, while once data is loaded the div containing pagination components appears below the data, in the second or so where the data is still loading the pagination components float to the top of the screen. I want to lock the position of the pagination components so a user doesn't see that movement. This is the css for the pagination component:
.pagination {
display: flex;
justify-content: flex-end;
}
What can I add to force this to position at the bottom of the page so it doesn't float to the top before the data loads? When I tried adding position: fixed and bottom: 0 it overrode other flex positioning and aligned left, when it should be right. So I want to use flex to do this - not standard css.
So, to summarize, I need this to force align right, AND align bottom.
.pagination {
display: flex;
justify-content: flex-end;
align-items: flex-end;
align-content: flex-end;
}
An initial setting of a flex container is flex-direction: row. This means that the main axis is horizontal and justify-content – which only works on the main axis – will align flex items horizontally.
For vertical alignment in a row-direction container use align-items (for a single line container, i.e., nowrap) and/or align-content (for a multiline container, i.e., wrap)

Difference between justify-content vs align-items? [duplicate]

This question already has answers here:
In CSS Flexbox, why are there no "justify-items" and "justify-self" properties?
(6 answers)
Closed 6 years ago.
I'm having a really hard time understanding what's the difference? From my research it seems like justify-content can do... space-between and space-around, while align-items can do... stretch, baseline, initial and inherit?
Also looks like both properties share, flex-start, flex-end and center.
Is there and dis/advantages to using one over the other or is it just preference? I feel like they are way to similar to just do the same thing anyone know the difference? thanks!!
Both set the alignment of the content.
1. justify-content: along primary axis
(set horizontal alignment/spacing if flex-direction is row or vertical alignment/spacing if flex-direction is column)
For instance, if flex-direction is row (default):
flex-start; Align children horizontally left
flex-end; Align children horizontally right
center; Align children horizontally centered (amaze!)
space-between; Distribute children horizontally evenly across entire width
space-around; Distribute children horizontally evenly across entire width (but with space on the edges
2. align-items: along secondary axis
(set vertical alignment if flex-direction is row or horizontal alignment if flex-direction is column)
For instance, if flex-direction is row (default):
flex-start; Align children vertically top
flex-end; Align children vertically bottom
center; Align children vertically centered (amaze!)
baseline; Aligned children vertically so their baselines align (doesn't really work)
stretch; Force children to be height of container (great for columns)
See it in action:
http://codepen.io/enxaneta/full/adLPwv/
In my opinion:
These should have been named:
flex-x: alignment/spacing in primary axis
flex-y: alignment in secondary axis
But with HTML you can never have nice things. Never.

Resources