Using Flexbox, how can you align elements to right?
Experience Level: Junior
Tags: CSSFlexbox
Answer
First you need to define a flex container. You do it by setting a CSS property display
to value flex
.
The default item flow orientation is horizontal so this is good for our case and we don't need to change it.
To align the item right, we will set a CSS property justify-content
to value flex-end
.
CSS
div {
display: flex;
justify-content: flex-end;
}
Related Flexbox job interview questions
Using Flexbox, how do you distribute items equally inside a container?
CSSFlexbox JuniorWhat CSS property does the value flex-end belong to and when would you use it?
CSSFlexbox JuniorWhat does justify-content CSS property do and what values can it have?
CSSFlexbox JuniorHow do you turn a html element into a flex container?
CSSFlexbox JuniorWhat is a relation between flex container and flex item?
CSSFlexbox Junior