The flex-direction property in CSS is used to set the direction in which flex items are laid out within a flex container. It determines whether the flex items are laid out in a row or a column, and whether they are arranged from left to right, right to left, top to bottom, or bottom to top.
The flex-direction property can be set to one of four values:
The flex-direction property affects both the main axis and the cross axis of the flex container. The main axis is the axis along which the flex items are laid out, and it is determined by the value of flex-direction. The cross axis is the perpendicular axis, and it is determined by the opposite value of flex-direction.
For example, if flex-direction: row, the main axis is horizontal, and the cross axis is vertical. If flex-direction: column, the main axis is vertical, and the cross axis is horizontal.
By using the flex-direction property, you can create flexible and responsive layouts for your web pages, allowing you to arrange elements in a way that best suits the content and design of your website. Additionally, you can use other flexbox properties such as justify-content, align-items, and flex-wrap to further control the layout and alignment of your flex items within the container.
The flex-direction: row property value in CSS is used to arrange the flex items within a flex container in a horizontal row, from left to right. It is the default value for the flex-direction property.
.container{ display: flex; flex-direction: row; }
When flex-direction is set to row, the main axis of the flex container is horizontal, and the cross axis is vertical. The flex items are arranged along the main axis, which is from left to right in this case.
Here are some key points to keep in mind when using flex-direction: row:
The flex-direction: row-reverse property value in CSS is used to arrange the flex items within a flex container in a horizontal row, from right to left.
.container{ display: flex; flex-direction: row-reverse; }
When flex-direction is set to row-reverse, the main axis of the flex container is horizontal, and the cross axis is vertical. The flex items are arranged along the main axis, which is from right to left in this case.
Here are some key points to keep in mind when using flex-direction: row-reverse:
Overall,flex-direction: row-reverse is a powerful tool in CSS for creating horizontal layouts that are flexible and responsive, allowing you to arrange elements in a way that best suits the content and design of your website, but in the opposite direction of flex-direction: row.
The flex-direction: column property value in CSS is used to arrange the flex items within a flex container in a vertical column, from top to bottom.
.container{ display: flex; flex-direction: column; }
When flex-direction is set to column, the main axis of the flex container is vertical, and the cross axis is horizontal. The flex items are arranged along the main axis, which is from top to bottom in this case.
Here are some key points to keep in mind when using flex-direction: column;
Overall, flex-direction: column is a powerful tool in CSS for creating vertical layouts that are flexible and responsive, allowing you to arrange elements in a way that best suits the content and design of your website.
The flex-direction: column-reverse property value in CSS is used to arrange the flex items within a flex container in a vertical column, from bottom to top.
.container{ display: flex; flex-direction: column-reverse; }
When flex-direction is set to column-reverse, the main axis of the flex container is vertical, and the cross axis is horizontal. The flex items are arranged along the main axis, which is from bottom to top in this case.
Here are some key points to keep in mind when using flex-direction: column-reverse:
Overall, flex-direction: column-reverse is a powerful tool in CSS for creating vertical layouts that are flexible and responsive, allowing you to arrange elements in a way that best suits the content and design of your website, but in the opposite direction of flex-direction: column.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <link rel="stylesheet" href="flex-direction.css"> </head> <body> <div class="container"> <div class="flex-item box-1">Box-1</div> <div class="flex-item box-2">Box-2</div> <div class="flex-item box-3">Box-3</div> <div class="flex-item box-4">Box-4</div> <div class="flex-item box-5">Box-5</div> <div class="flex-item box-6">Box-6</div> <div class="flex-item box-7">Box-7</div> <div class="flex-item box-8">Box-8</div> <div class="flex-item box-9">Box-9</div> </div> </body> </html>
@import url('https://fonts.googleapis.com/css2?family=Rubik:wght@300;400;500;600;700;900&display=swap'); *{ margin: 0; padding: 0; font-family: 'Rubik', sans-serif; } .container{ border:5px solid black; } .flex-item{ color:white; font-size: 18px; padding: 16px; text-align: center; } .box-1{background-color: #1abc9c;} .box-2{background-color:#3498db;} .box-3{background-color: #2ecc71;} .box-4{background-color: #9b59b6;} .box-5{background-color:#34495e;} .box-6{background-color:#2980b9;} .box-7{background-color:#e74c3c;} .box-8{background-color: #d35400;} .box-9{background-color:#2c3e50;} /*-----------------------------------*/ .container{ display: flex; flex-direction: row; flex-direction: row-reverse; flex-direction: column; flex-direction: column-reverse; }Live Preview
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions