{"id":23850,"date":"2022-11-15T07:58:37","date_gmt":"2022-11-15T15:58:37","guid":{"rendered":"https:\/\/coderpad.io\/?p=23850"},"modified":"2023-06-05T13:51:43","modified_gmt":"2023-06-05T20:51:43","slug":"a-guide-to-css-flexbox","status":"publish","type":"post","link":"https:\/\/coderpad.io\/blog\/development\/a-guide-to-css-flexbox\/","title":{"rendered":"A Guide to CSS Flexbox"},"content":{"rendered":"\n<p>When you add HTML content to your web page, it stacks on top of itself, leaving a lot of space on the edges or making your content look odd. The <code>float<\/code> CSS property, along with <code>position<\/code>, was then used to define layouts and position elements, but it was complicated to use, especially when dealing with responsiveness.<\/p>\n\n\n\n<p>You no longer need to use the float and position properties to organize your page&#8217;s layout and style containers or content side by side. With the advancement of the web and technology, you now have two CSS layout systems: flexbox and CSS grid. This guide focuses on CSS flexbox, but you can bookmark our <a href=\"https:\/\/coderpad.io\/blog\/development\/a-very-very-in-depth-guide-on-css-grid\/\">detailed guide on CSS grid<\/a>.<\/p>\n\n\n\n<p>This guide will teach you everything you need to know about the CSS flexbox layout system, including the flexbox layout axis and its properties, justifying and aligning flex items, adding gaps and ordering these elements, and much more. You&#8217;ll also learn when to use flexbox and when to use CSS grid by the end of this guide.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is Flexbox?<\/h2>\n\n\n\n<p>CSS flexbox is a one-dimensional layout system that you can use to create a row or column axis layout. It is a module rather than a single property because it includes several properties, some of which are for the flex container (parent element) and others for the flex items (children elements). This layout module allows the container to change its items&#8217; width\/height (and order) to fit the available space best and support all display devices and screen sizes.<\/p>\n\n\n\n<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/CSS_Flexible_Box_Layout\" target=\"_blank\" rel=\"noopener\">CSS flexbox was introduced in 2009<\/a> as a new layout system to make it easier to build responsive web pages and organize your elements, and it has grown in popularity since then. Flex is designed to provide a more efficient way of laying out all items, aligning, and distributing space among each item in a container, even when each flex item&#8217;s sizes are unknown and\/or dynamic.<\/p>\n\n\n\n<p>It simplifies designing and building responsive web pages by eliminating the need for tricky hacks and a plethora of float and position properties in your CSS code. Flexbox allows you to automatically scale elements (change their height or width) to fill the available space, shrink or grow elements to fit into the container, and prevent overflow. It can change the order of the items, create columns of the same height, design navigation panels, and much more.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Understand the Flexbox Layout Axis<\/h2>\n\n\n\n<p>The way items are laid out when you use flexbox is based on the flex directions. If the <code>flex-direction<\/code> is <code>row<\/code> which is the default value, your main axis is along the row, and your cross-axis is along the column. If the <code>flex-direction<\/code> is <code>column<\/code>, your main axis is along the column while your cross-axis is along the row.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/d2h1bfu6zrdxog.cloudfront.net\/wp-content\/uploads\/2022\/11\/img_63737615eca13.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">By default, the main axis goes horizontally across the container, and the cross-axis goes vertically.<\/figcaption><\/figure>\n\n\n\n<p>The primary axis in which flex items are laid out in a flex container is usually referred to as the main axis. It is not necessarily horizontal because it depends on the <code>flex-direction<\/code> property. The cross-axis is perpendicular to the main axis. Its direction depends on the main-axis direction.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Flexbox properties<\/h2>\n\n\n\n<p>Flexbox is a module, meaning it comprises many properties that are either applied to the flexbox container or the flex items. Here is a table to show the list of elements that you can apply to either the flex container or items:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>Flex container<\/strong><\/td><td><strong>Flex Items<\/strong><\/td><\/tr><tr><td>display<\/td><td>order<\/td><\/tr><tr><td>flex-direction<\/td><td>flex-grow<\/td><\/tr><tr><td>flex-wrap<\/td><td>flex-shrink<\/td><\/tr><tr><td>flex-flow<\/td><td>flex-basis<\/td><\/tr><tr><td>justify-content<\/td><td>flex<\/td><\/tr><tr><td>align-items<\/td><td>align-self<\/td><\/tr><tr><td>align-content<\/td><td><\/td><\/tr><tr><td>gap, row-gap, column-gap<\/td><td><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">How to make a flex container<\/h2>\n\n\n\n<p>The flex container is a container that holds all the flex items. For example, if you have a <code>div<\/code> that holds three other divs:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml shcb-wrap-lines\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"flex-container\"<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"flex-item\"<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">p<\/span>&gt;<\/span>Item One<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">p<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"flex-item\"<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">p<\/span>&gt;<\/span>Item Two<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">p<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"flex-item\"<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">p<\/span>&gt;<\/span>Item Three<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">p<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>To make the parent div a flex container, you would apply the display property and give it a value flex. This turns the container into a block element, allowing a flex layout for all of its direct children.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css shcb-wrap-lines\"><span class=\"hljs-selector-class\">.flex-container<\/span> {\n    <span class=\"hljs-attribute\">display<\/span>: flex;\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>You can also set the value to <code>inline-flex<\/code>, which works similarly. The only difference is that it creates a container as an inline element.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css shcb-wrap-lines\"><span class=\"hljs-selector-class\">.flex-container<\/span> {\n    <span class=\"hljs-attribute\">display<\/span>: inline-flex;\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<blockquote class=\"wp-block-quote\">\n<p>\ud83d\udca1 An absolutely-positioned flex item does not participate in flex layout.<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">How to set flex-direction<\/h2>\n\n\n\n<p>You can set the direction of your flex items using the <code>flex-direction<\/code> property. You can set the items to flex vertically (<code>column<\/code>), horizontally (<code>row<\/code>), or even reverse the items in the specified direction using values like <code>row-reverse<\/code> and <code>column-reverse<\/code>.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css shcb-wrap-lines\"><span class=\"hljs-selector-class\">.flex-container<\/span> {\n    <span class=\"hljs-attribute\">display<\/span>: flex;\n    <span class=\"hljs-attribute\">flex-direction<\/span>: row | row-reverse | column | column-reverse;\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The <code>flex-direction<\/code> property will only work on a flex container, meaning you must have used the <code>display<\/code> property and set the value to <code>flex<\/code> or <code>inline-flex<\/code>.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/d2h1bfu6zrdxog.cloudfront.net\/wp-content\/uploads\/2022\/11\/img_63737617b0b21.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">A pictorial representation of what flex-direction row and column does<\/figcaption><\/figure>\n\n\n\n<p>The default value of <code>flex-direction<\/code> is <code>row<\/code> which sets the flex items from left to right. In contrast, <code>row-reverse<\/code> does the opposite and sets flex items right to left. <code>column<\/code> will set flex items from top to bottom with items order similar to row, while <code>column-reverse<\/code> will reverse the flex items from bottom to top.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping flex Items<\/h2>\n\n\n\n<p>When you create a flex container, all its items (flex items) will try to fit onto one line by default. When these items reach the max-width, they shrink to fit onto that single line.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/d2h1bfu6zrdxog.cloudfront.net\/wp-content\/uploads\/2022\/11\/img_63737618d5134.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">Flex items shrink on one line by default when you create a flex container.&nbsp;<\/figcaption><\/figure>\n\n\n\n<p>You can change that and let the items wrap as needed with the <code>flex-wrap<\/code> property. This property has three values, but the wrapped value will help avoid your flex items from shrinking onto one line.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css shcb-wrap-lines\"><span class=\"hljs-selector-class\">.flex-container<\/span> {\n    <span class=\"hljs-attribute\">display<\/span>: flex;\n    <span class=\"hljs-attribute\">flex-wrap<\/span>: wrap;\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/d2h1bfu6zrdxog.cloudfront.net\/wp-content\/uploads\/2022\/11\/img_6373761a8aaae.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">Wrap helps ensure even when the items flex, they maintain their regular size.<\/figcaption><\/figure>\n\n\n\n<p>There are two other values, <code>nowrap<\/code> and <code>wrap-reverse<\/code>. <code>wrap<\/code> will help you wrap your items onto multiple lines, from top to bottom, rather than compressing all flex items to one line. While the default value of <code>nowrap<\/code> causes all flex items to shrink onto one line, <code>wrap-reverse<\/code> causes the flex items to wrap across multiple lines from bottom to top.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/d2h1bfu6zrdxog.cloudfront.net\/wp-content\/uploads\/2022\/11\/img_6373761e448e6.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">A representation of the various flex-wrap values and how they work.<\/figcaption><\/figure>\n\n\n\n<p>So far, you have learned two significant properties: <code>flex-direction<\/code> and <code>flex-wrap. <\/code>If you need to use both properties, then you can use<code> <\/code>the <code>flex-flow<\/code> shorthand property.&nbsp;<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css shcb-wrap-lines\"><span class=\"hljs-selector-class\">.flex-container<\/span> {\n    <span class=\"hljs-attribute\">display<\/span>: flex;\n    <span class=\"hljs-attribute\">flex-flow<\/span>: column wrap;\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">How to align items along the main axis<\/h2>\n\n\n\n<p>The <code>justify-content<\/code> property defines the horizontal alignment of flex items. This property has six major values that perform individual functions, all aimed at exerting some control over the alignment of flex items.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css shcb-wrap-lines\"><span class=\"hljs-selector-class\">.flex-container<\/span> {\n    <span class=\"hljs-attribute\">justify-content<\/span>: flex-start | flex-end | center | space-between | space-around | space-evenly;\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<ul class=\"wp-block-list\">\n<li><code>flex-start<\/code>: This is the default value in which flex items are packed toward the start of the main axis or <code>flex-direction<\/code>.<\/li>\n\n\n\n<li><code>flex-end<\/code>: This is the opposite of <code>flex-start<\/code>, as flex items are packed toward the end of the main axis or <code>flex-direction<\/code>.<\/li>\n\n\n\n<li><code>center<\/code>: This perfectly fits the flex items within the flex container. Other options, such as start, end, left, and right, do what the value indicates. For example, when you set a value to <code>right<\/code>, the flex items will be packed toward the container&#8217;s right edge.<\/li>\n\n\n\n<li><code>space-between<\/code>: This option evenly distributes flex items in the line starting and ending on the flex container border, except for padding or margin.<\/li>\n\n\n\n<li><code>space-around<\/code>: This option will evenly distribute flex items in line with equal space around them (left, right, bottom and top). It is important to know that between each element, the gap won&#8217;t be the same as the top and bottom because this is the sum of the gap on the right and left of both elements.<\/li>\n\n\n\n<li><code>space-evenly<\/code>: This creates an exact space between each flex item, ensuring that the space between any two items and the edges is equal.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/d2h1bfu6zrdxog.cloudfront.net\/wp-content\/uploads\/2022\/11\/img_6373761fe1f63.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">The various values of justify-content and how they help justify flex items.<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">How to align items along the cross-axis<\/h2>\n\n\n\n<p>Asides from aligning items along the main axis, you can also do for the cross-axis using the <code>align-items<\/code> property. Just like the <code>justify-content<\/code> property, <code>align-items<\/code> also has about five values that can be used to align flex items.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css shcb-wrap-lines\"><span class=\"hljs-selector-class\">.flex-container<\/span> {\n    <span class=\"hljs-attribute\">display<\/span>: flex;\n    <span class=\"hljs-attribute\">align-items<\/span>: stretch | flex-start | flex-end | center | baseline;\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<ul class=\"wp-block-list\">\n<li><code>stretch<\/code>: By default, flex items are stretched to fill the flex container, still respecting <code>min-width<\/code> and <code>max-width<\/code> properties.<\/li>\n\n\n\n<li><code>flex-start<\/code>: This places all flex items at the start of the cross-axis based on the <code>flex-direction<\/code>. Other values similar to this are <code>start<\/code> and <code>self-start<\/code>.<\/li>\n\n\n\n<li><code>flex-end<\/code>: This is the opposite of <code>flex-start<\/code>, as flex items are placed at the end of the cross-axis. Other values similar to this are <code>end<\/code> and <code>self-end<\/code>.<\/li>\n\n\n\n<li><code>center<\/code>: This places flex items in the center along the cross-axis.<\/li>\n\n\n\n<li><code>baseline<\/code>: All flex items are aligned in the sense that their baselines are aligned.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/d2h1bfu6zrdxog.cloudfront.net\/wp-content\/uploads\/2022\/11\/img_63737620bb92c.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">align-item helps align flex items to various positions as shown in this image<\/figcaption><\/figure>\n\n\n\n<p><code>align-items<\/code> works with the one-line flex items, while you can use the <code>align-content<\/code> property to define the vertical alignment of <strong>multiple lines of items<\/strong>. This property has no effect when only one line of flex items exists.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\">\n<p>\u2139\ufe0f In multiple line flexible containers, the <code>align-content<\/code> property will not work unless <code>flex-wrap<\/code> is set to <code>wrap<\/code> or <code>wrap-reverse<\/code>.&nbsp;<\/p>\n<\/blockquote>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css shcb-wrap-lines\"><span class=\"hljs-selector-class\">.flex-container<\/span> {\n    <span class=\"hljs-attribute\">display<\/span>: flex;\n    <span class=\"hljs-attribute\">align-content<\/span>: stretch | flex-start | flex-end | center | space-between | space-around;\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The <code>justify-content<\/code> property is used to align individual items on the main axis, but you can also use <code>align-content<\/code> for the cross-axis when you want to space the items, move them to the start or end of the cross-axis, or stretch them.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>flex-start<\/code>: This can be used to move all your flex items to the start of the flex container based on the <code>flex-direction<\/code>. This is also similar to using <code>start<\/code>.<\/li>\n\n\n\n<li><code>flex-end<\/code> \/ <code>end<\/code>: This is the opposite of <code>flex-start<\/code> or <code>start<\/code>. The flex items are moved to the end of the flex container. This is also similar to using <code>end<\/code>.<\/li>\n\n\n\n<li><code>center<\/code>: All flex items are placed at the center of the flex container.<\/li>\n\n\n\n<li><code>space-between<\/code>: This will space all flex items evenly, starting and ending on the edge of the flex container.<\/li>\n\n\n\n<li><code>space-around<\/code>: This helps you evenly distribute equal space around each flex item. You can also make use of <code>space-evenly<\/code> for perfect spacing.<\/li>\n\n\n\n<li><code>stretch<\/code>: flex items are stretched to take up the entire space.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/d2h1bfu6zrdxog.cloudfront.net\/wp-content\/uploads\/2022\/11\/img_637376223f744.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">Illustration of how align-content helps position flex items in your flex container<\/figcaption><\/figure>\n\n\n\n<p>So far, you have learned how to align all flex items through the container element. But it is important to know that you can also align each item individually using the <code>align-self<\/code> property. The <code>align-items<\/code> property allows you to override the alignment specified for the flex container.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css shcb-wrap-lines\"><span class=\"hljs-selector-class\">.flex-item<\/span> {\n    <span class=\"hljs-attribute\">align-self<\/span>: stretch | flex-start | flex-end | center | baseline;\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The <code>align-self<\/code> property has the same values and meaning as <code>align-items<\/code>. Here&#8217;s an example of what happens when you give each flex item its own align-self value.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/d2h1bfu6zrdxog.cloudfront.net\/wp-content\/uploads\/2022\/11\/img_637376237a1aa.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\"><code>align-self<\/code> is used to align each item individually. The image shows each flex item having different values.<\/figcaption><\/figure>\n\n\n\n<p>This property is used when you need to add specific alignment to an individual flex item different from other flex items.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Gapping flex items horizontally and vertically<\/h2>\n\n\n\n<p>At this point, one major aspect left for your flex container styling is adding gaps to your flex items. You will want to be able to add equal gaps between flex items either horizontally, vertically, or on both sides.<\/p>\n\n\n\n<p>You can do this with the <code>gap<\/code> property. The <code>gap<\/code> property controls the amount of space between each flex item. The gap or spacing is only applied between the flex items and not on the outer edges. This property is for more than just flexbox, as it works in grid and multi-column layouts.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css shcb-wrap-lines\"><span class=\"hljs-selector-class\">.flex-container<\/span> {\n    <span class=\"hljs-attribute\">display<\/span>: flex;\n    <span class=\"hljs-attribute\">gap<\/span>: <span class=\"hljs-number\">20px<\/span>;\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/d2h1bfu6zrdxog.cloudfront.net\/wp-content\/uploads\/2022\/11\/img_6373762415326.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">The gap property adds equal gaps between nine flex items.<\/figcaption><\/figure>\n\n\n\n<p>The <code>gap<\/code> property is a shorthand that you can use to specify one value for both the column and rows. When you want different values, you can use two values. The first is the row, while the second is for the column. Finally, you can use two properties: <code>row-gap<\/code> and <code>column-gap<\/code>.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-12\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\">.flex-container {\n    <span class=\"hljs-attr\">display<\/span>: flex;\n    <span class=\"hljs-comment\">\/\/ ...<\/span>\n    gap: <span class=\"hljs-number\">20<\/span>px;\n    gap: <span class=\"hljs-number\">20<\/span>px <span class=\"hljs-number\">30<\/span>px; <span class=\"hljs-comment\">\/* row-gap column gap *\/<\/span>\n    row-gap: <span class=\"hljs-number\">20<\/span>px;\n    column-gap: <span class=\"hljs-number\">30<\/span>px;\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-12\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/d2h1bfu6zrdxog.cloudfront.net\/wp-content\/uploads\/2022\/11\/img_63737624f2960.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">Illustration shows apply gap either to the row or to the column.<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Ordering elements<\/h2>\n\n\n\n<p>You can use the order property to assign how flex items are ordered. You will use integer values to lay out these items from lowest to highest. When flex items have the same <code>order<\/code>, it will revert to the source order.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-13\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css shcb-wrap-lines\"><span class=\"hljs-selector-class\">.flex-item<\/span> {\n    <span class=\"hljs-attribute\">order<\/span>: <span class=\"hljs-number\">5<\/span>;\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-13\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>For example, if you have four items, you can specify how you want them to be ordered by giving them an order value:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>flex item 1: <code>order: 3<\/code><\/li>\n\n\n\n<li>flex item 2: <code>order: 1<\/code><\/li>\n\n\n\n<li>flex item 3: <code>order: 1<\/code><\/li>\n\n\n\n<li>flex item 4: <code>order: 2<\/code><\/li>\n<\/ul>\n\n\n\n<p>The items above would be displayed in the following order, based on the value you set:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>flex item 2: <code>order: 1<\/code><\/li>\n\n\n\n<li>flex item 3: <code>order: 1<\/code><\/li>\n\n\n\n<li>flex item 4: <code>order: 2<\/code><\/li>\n\n\n\n<li>flex item 1: <code>order: 3<\/code><\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/d2h1bfu6zrdxog.cloudfront.net\/wp-content\/uploads\/2022\/11\/img_63737625d0c77.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">Four items are arranged in the order two, three, four and one<\/figcaption><\/figure>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-14\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css shcb-wrap-lines\"><span class=\"hljs-selector-class\">.item1<\/span> {\n    <span class=\"hljs-attribute\">order<\/span>: <span class=\"hljs-number\">3<\/span>;\n}\n<span class=\"hljs-selector-class\">.item2<\/span> {\n    <span class=\"hljs-attribute\">order<\/span>: <span class=\"hljs-number\">1<\/span>;\n}\n<span class=\"hljs-selector-class\">.item3<\/span> {\n    <span class=\"hljs-attribute\">order<\/span>: <span class=\"hljs-number\">1<\/span>;\n}\n<span class=\"hljs-selector-class\">.item4<\/span> {\n    <span class=\"hljs-attribute\">order<\/span>: <span class=\"hljs-number\">2<\/span>;\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-14\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Sizing flex items &#8211; grow and shrink<\/h2>\n\n\n\n<p>Sizing flex items and making them flexible depends on three flex item properties: <code>flex-basis<\/code>, <code>flex-grow<\/code>, and <code>flex-shrink<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">flex-basis<\/h3>\n\n\n\n<p>This property specifies the length of flex items or individual flex items. This overrides any previously defined width for that element. This accepts length values (e.g., 10%, 4rem, etc.) and can also use <code>auto<\/code>, which uses the declared width value.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-15\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css shcb-wrap-lines\"><span class=\"hljs-selector-class\">.flex-item<\/span> {\n    <span class=\"hljs-attribute\">flex-basis<\/span>: &lt;length&gt; | auto ;\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-15\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<blockquote class=\"wp-block-quote\">\n<p>\ud83d\udca1 The `flex-basis` property has no effect if the element or item is not a flex item. This means that if it is not contained within a flex container.<\/p>\n<\/blockquote>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/d2h1bfu6zrdxog.cloudfront.net\/wp-content\/uploads\/2022\/11\/img_637376270d923.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\"><code>flex-basis<\/code> helps define the width each flex item takes in the flex container<\/figcaption><\/figure>\n\n\n\n<p>The flex container in the image above is wrapped, which means that when it reaches the edge, the items will fall to the new line. The <code>flex-basis<\/code> property is then applied to the flex items and set to 30%, meaning each item will take up 30% of the total width, leaving 10%. You can use the <code>flex-grow<\/code> property to help the elements grow and cover up small spaces that cannot accept new flex items.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">flex-grow<\/h3>\n\n\n\n<p>You can apply the <code>flex-grow<\/code> property to individual flex items or all flex items simultaneously. It defines a flex item&#8217;s ability to grow. It ensures that flex items fill the available space inside the flex container by causing each item to grow following the supplied value. It has a default value of 0 and accepts a unitless value (e.g., 1, 2, 3 &#8230;) as a proportion.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\">\n<p>\u2139\ufe0f Negative numbers are invalid.<\/p>\n<\/blockquote>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-16\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css shcb-wrap-lines\"><span class=\"hljs-selector-class\">.flex-item<\/span> {\n    <span class=\"hljs-attribute\">flex-grow<\/span>: <span class=\"hljs-number\">1<\/span> ;\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-16\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>If all of your flex items (perhaps with the same class name) have their <code>flex-grow<\/code> set to 1, the container&#8217;s remaining space will be distributed evenly to all flex items.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/d2h1bfu6zrdxog.cloudfront.net\/wp-content\/uploads\/2022\/11\/img_6373762aec93a.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\"><code>flex-grow<\/code> ensures that the flex items stretch to fill the space in the flex container.<\/figcaption><\/figure>\n\n\n\n<p>If an item&#8217;s <code>flex-grow<\/code> value is set to 2, it will gain twice the width of other items with <code>flex-grow<\/code> values of 1.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-17\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css shcb-wrap-lines\"><span class=\"hljs-selector-class\">.item1<\/span> {\n    <span class=\"hljs-attribute\">flex-grow<\/span>: <span class=\"hljs-number\">2<\/span>;\n}\n<span class=\"hljs-selector-class\">.item2<\/span> {\n    <span class=\"hljs-attribute\">flex-grow<\/span>: <span class=\"hljs-number\">1<\/span>;\n}\n<span class=\"hljs-selector-class\">.item3<\/span> {\n    <span class=\"hljs-attribute\">flex-grow<\/span>: <span class=\"hljs-number\">1<\/span>;\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-17\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/d2h1bfu6zrdxog.cloudfront.net\/wp-content\/uploads\/2022\/11\/img_6373762de1262.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">The first flex item has a larger width due to the <code>flex-grow<\/code> value set to a higher number than the second and third items.<\/figcaption><\/figure>\n\n\n\n<p>This will work when the <code>flex-basis<\/code> is not set to any specific value.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">flex-shrink<\/h3>\n\n\n\n<p>The <code>flex-shrink<\/code> property applies to flex items and specifies how much it will shrink each element if insufficient space exists. It has a default value of 1 and accepts a unitless value (e.g., 1, 2, 3) as a proportion.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\">\n<p>\u2139\ufe0f When set to 0, the flex item retains its original size. Negative numbers are invalid.<\/p>\n<\/blockquote>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-18\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css shcb-wrap-lines\"><span class=\"hljs-selector-class\">.flex-item<\/span> {\n    <span class=\"hljs-attribute\">flex-shrink<\/span>: <span class=\"hljs-number\">2<\/span>;\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-18\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>When you set a specific width for each flex item, and the sum of the width plus the gap surpasses the flex container width, you can use <code>flex-shrink<\/code> to indicate how much each element will be reduced.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-19\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css shcb-wrap-lines\"><span class=\"hljs-selector-class\">.item1<\/span> {\n    <span class=\"hljs-attribute\">flex-basis<\/span>: <span class=\"hljs-number\">150px<\/span>;\n    <span class=\"hljs-attribute\">flex-shrink<\/span>: <span class=\"hljs-number\">1<\/span>;\n}\n<span class=\"hljs-selector-class\">.item2<\/span> {\n    <span class=\"hljs-attribute\">flex-basis<\/span>: <span class=\"hljs-number\">250px<\/span>;\n    <span class=\"hljs-attribute\">flex-shrink<\/span>: <span class=\"hljs-number\">2<\/span>;\n}\n<span class=\"hljs-selector-class\">.item3<\/span> {\n    <span class=\"hljs-attribute\">flex-basis<\/span>: <span class=\"hljs-number\">350px<\/span>;\n    <span class=\"hljs-attribute\">flex-shrink<\/span>: <span class=\"hljs-number\">3<\/span>;\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-19\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/d2h1bfu6zrdxog.cloudfront.net\/wp-content\/uploads\/2022\/11\/img_6373762f52193.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">The boxes have different shrink length as a consequence of the values set.<\/figcaption><\/figure>\n\n\n\n<blockquote class=\"wp-block-quote\">\n<p>\u2139\ufe0f <code>flex-shrink<\/code> won&#8217;t work if the flex container has the <code>flex-wrap<\/code> property set to <code>wrap<\/code>.<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">The flex shorthand for better syntax<\/h3>\n\n\n\n<p>Finally, you have learned that you can use these three properties to size your flex items. Instead of using three properties, you can combine its value using the <code>flex<\/code> property. It is a shorthand for <code>flex-grow<\/code>, <code>flex-shrink<\/code>, and <code>flex-basis<\/code> combined.&nbsp;<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\">\n<p>\ud83d\udca1 <code>flex-shrink<\/code>, and <code>flex-basis<\/code> are optional.<\/p>\n<\/blockquote>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-20\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css shcb-wrap-lines\"><span class=\"hljs-selector-class\">.flex-item<\/span> {\n    <span class=\"hljs-attribute\">flex<\/span>: none | &#91; &lt;<span class=\"hljs-string\">'flex-grow'<\/span>&gt; &lt;<span class=\"hljs-string\">'flex-shrink'<\/span>&gt;? || &lt;<span class=\"hljs-string\">'flex-basis'<\/span>&gt; ];\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-20\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The default value for flex property is <code>0 1 auto<\/code>, but if you use a single number value:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-21\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css shcb-wrap-lines\"><span class=\"hljs-selector-class\">.flex-item<\/span> {\n    <span class=\"hljs-attribute\">flex<\/span>: <span class=\"hljs-number\">2<\/span>;\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-21\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>This changes the <code>flex-basis<\/code> to <code>0%<\/code>, so it&#8217;s like setting:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-22\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css shcb-wrap-lines\"><span class=\"hljs-selector-class\">.flex-item<\/span> {\n    <span class=\"hljs-attribute\">flex-grow<\/span>: <span class=\"hljs-number\">2<\/span>;\n    <span class=\"hljs-attribute\">flex-shrink<\/span>: <span class=\"hljs-number\">1<\/span>;\n    <span class=\"hljs-attribute\">flex-basis<\/span>: <span class=\"hljs-number\">0%<\/span>;\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-22\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>It is always recommended that you use this shorthand property because it intelligently sets the other values.<br><br>Play with CSS flexbox in the sandbox below:<\/p>\n\n\n<div\n\tclass=\"sandbox-embed responsive-embed  sandbox-embed--full-width\"\n\tstyle=\"padding-top: 125%\"\ndata-block-name=\"coderpad-sandbox-embed\">\n\t<iframe src=\"https:\/\/embed.coderpad.io\/sandbox?question_id=235058&#038;use_question_button\" width=\"640\" height=\"800\" loading=\"lazy\" aria-label=\"Try out the CoderPad sandbox\"><\/iframe>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">When to use flexbox over CSS grid<\/h2>\n\n\n\n<p>So far, you&#8217;ve learned what flexbox is, what it does, how it works, and that it&#8217;s a CSS layout system similar to CSS grid. Then you wonder, do I choose one, or is there a situation where you must use flexbox over grid?<\/p>\n\n\n\n<p>It would be best to use CSS flexbox when you have a small design to implement with a few rows or columns. Also, when you need to align elements, flexbox comes in handy.<\/p>\n\n\n\n<p>You can certainly build your entire website or application using only flexbox and achieve the same results as if you were using CSS grid, which is perfectly fine. However, for a better CSS approach, you must write codes that are clean, maintainable, and easy for others to manage over time. CSS grid is the best way to create and fit your layout perfectly.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\">\n<p>\u2139\ufe0f The flexbox layout is best suited for application components and small-scale layouts, whereas the <strong><a href=\"https:\/\/coderpad.io\/blog\/development\/a-very-very-in-depth-guide-on-css-grid\/\">grid<\/a><\/strong> layout is best suited for larger scale layouts.<\/p>\n<\/blockquote>\n\n\n\n<p>Learn more about CSS grid in this <a href=\"https:\/\/coderpad.io\/blog\/development\/a-very-very-in-depth-guide-on-css-grid\/\">very in-depth guide<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping up<\/h2>\n\n\n\n<p>In this guide, you have learned what the CSS flexbox is all about, how it works and the various elements that you can use to help you create an awesome layout for your small projects.<\/p>\n\n\n\n<p>There are so many instances when you\u2019d need to make use of the CSS flexbox such as centering items, on your navbar, basic horizontal layouts and lots more. Having a proper understanding of each CSS property and their values will help you.<\/p>\n\n\n\n<p>Have fun coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>With the advancement of the web and technology, you can now use CSS flexbox to organize your page layout and style your containers. This guide will teach you everything you need to know about the CSS Flexbox layout system, including the flexbox layout axis and its properties, justifying and aligning flex items, adding gaps and ordering these elements, and much more.<\/p>\n","protected":false},"author":1,"featured_media":23892,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[9],"tags":[],"persona":[29],"blog-programming-language":[62],"keyword-cluster":[],"class_list":["post-23850","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-development"],"acf":[],"_links":{"self":[{"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/posts\/23850","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/comments?post=23850"}],"version-history":[{"count":103,"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/posts\/23850\/revisions"}],"predecessor-version":[{"id":32622,"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/posts\/23850\/revisions\/32622"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/media\/23892"}],"wp:attachment":[{"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/media?parent=23850"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/categories?post=23850"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/tags?post=23850"},{"taxonomy":"persona","embeddable":true,"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/persona?post=23850"},{"taxonomy":"blog-programming-language","embeddable":true,"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/blog-programming-language?post=23850"},{"taxonomy":"keyword-cluster","embeddable":true,"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/keyword-cluster?post=23850"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}