Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Align items to left while flex direction is row-reverse in Flex

I want to display items in reverse order horizontally with left alignment

here is my working fiddle, but items are aligned to right.

#main {
    width: 400px;
    height: 400px;
    border: 1px solid #c3c3c3;
    display: flex;
    flex-direction: row-reverse;
    align-items: flex-start;
}

#main div {
    width: 50px;
    height: 50px;
}
<div id="main">
  <div style="background-color:coral;">A</div>
  <div style="background-color:lightblue;">B</div>
  <div style="background-color:khaki;">C</div>
  <div style="background-color:pink;">D</div>
  <div style="background-color:lightgrey;">E</div>
  <div style="background-color:lightgreen;">F</div>
</div>

can someone help me, thanks in advance.

like image 595
satish kumar V Avatar asked Oct 04 '18 09:10

satish kumar V


People also ask

What does flex-direction row-reverse do?

Using the flex-direction property with values of row-reverse or column-reverse will create a disconnect between the visual presentation of content and DOM order.

How do you reverse flex-direction?

default flex-direction: row; The flexbox items are ordered the same way as the text direction, along the main axis. flex-direction: row-reverse; The flexbox items are ordered the opposite way as the text direction, along the main axis.

How do you align left and right on flex?

The flex columns can be aligned left or right by using the align-content property in the flex container class. The align-content property changes the behavior of the flex-wrap property. It aligns flex lines. It is used to specify the alignment between the lines inside a flexible container.

How to align the Flex columns left or right in CSS?

The flex columns can be aligned left or right by using the align-content property in the flex container class. The align-content property changes the behavior of the flex-wrap property. It aligns flex lines.

How to align the Flex columns in a flex container?

The flex columns can be aligned left or right by using the align-content property in the flex container class. The align-content property changes the behavior of the flex-wrap property. It aligns flex lines. It is used to specify the alignment between the lines inside a flexible container.

How do I align items to the left and right?

If we change our flex-direction to column, align-items and align-self will align the items to the left and right. You can try this out in the example below, which has a flex container with flex-direction: column yet otherwise is exactly the same as the previous example.

What is the use of flex direction in Flexbox?

Flexbox - Flex-Direction. The flex-direction property is used to specify the direction in which the elements of flex container (flex-items) are needed to be placed. row − Arranges the elements of the container horizontally from left to right. row-reverse − Arranges the elements of the container horizontally from right to left.


1 Answers

You need to specify justify-content: flex-end;

#main {
  width: 400px;
  height: 400px;
  border: 1px solid #c3c3c3;
  display: flex;
  flex-direction: row-reverse;
  align-items: flex-start;
  justify-content: flex-end;
}

#main div {
  width: 50px;
  height: 50px;
}
<div id="main">
  <div style="background-color:coral;">A</div>
  <div style="background-color:lightblue;">B</div>
  <div style="background-color:khaki;">C</div>
  <div style="background-color:pink;">D</div>
  <div style="background-color:lightgrey;">E</div>
  <div style="background-color:lightgreen;">F</div>
</div>
like image 159
Paulie_D Avatar answered Oct 02 '22 23:10

Paulie_D