Photo by Pankaj Patel on Unsplash
Flex Box (CSS)
In this article we'll talk about Flex Box used in CSS(Cascading Style Sheets).
Table of contents
CSS (Cascading Style Sheets) is used to style and layout the content of web pages. Flexbox is a layout mode in CSS that allows you to create flexible and responsive layouts for your web pages.
Flexbox is a powerful layout mode in CSS that allows you to create flexible and responsive layouts for your web pages. By using flex containers and flex items, you can control the layout and order of the content on your web page. With a little bit of practice, you can use Flexbox to create beautiful and dynamic layouts that will impress your website visitors. In this article, we will explain the basics of using Flexbox in CSS.
Flex Container
To use Flexbox, you first need to create a flex container. To create a flex container, use the display property and set it to "flex". For example:
<div class="flex-container">
<div class="flex-item">Item 1</div>
<div class="flex-item">Item 2</div>
<div class="flex-item">Item 3</div>
</div>
<style>
.flex-container {
display: flex;
}
.flex-item {
/* Add styles for flex items here */
}
</style>
In the example above, the element with the class "flex-container" is set to display:flex. This makes it a flex container, and its child elements become flex items.
Flex Items
Once you have created a flex container, you can control the layout of the flex items. To control the layout of the flex items, use the flex property. For example:
.flex-item {
flex: 1;
}
In the example above, the flex property is set to 1 for all flex items. This means that they will be distributed evenly across the width of the flex container.
Order
You can also control the order of the flex items using the order property. For example:
.flex-item:nth-child(2) {
order: 1;
}
In the example above, the second flex item is set to order 1. This means that it will appear before the third flex item, even though it is listed after it in the HTML.