Flexbox – Flex-Wrap ”; Previous Next Generally, in case of insufficient space for the container, the rest of the flex items will be hidden as shown below. The flex-wrap property is used to specify the controls whether the flex-container is single-line or multi-line. usage − flex-wrap: nowrap | wrap | wrap-reverse flex-direction: column | column-reverse This property accepts the following values − wrap − In case of insufficient space for them, the elements of the container (flexitems) will wrap into additional flex lines from top to bottom. wrap-reverse − In case of insufficient space for them, the elements of the container (flex-items) will wrap into additional flex lines from bottom to top. Now, we will see how to use the wrap property, with examples. wrap On passing the value wrap to the property flex-wrap, the elements of the container are arranged horizontally from left to right as shown below. The following example demonstrates the result of passing the value wrap to the flex-wrap property. Here, we are creating six boxes with different colors with the flex-direction value row. Live Demo <!doctype html> <html lang = “en”> <style> .box1{background:green;} .box2{background:blue;} .box3{background:red;} .box4{background:magenta;} .box5{background:yellow;} .box6{background:pink;} .box{ font-size:35px; padding:15px; width:100px; } .container{ display:flex; border:3px solid black; flex-direction:row; flex-wrap:wrap; } </style> <body> <div class = “container”> <div class = “box box1”>One</div> <div class = “box box2”>two</div> <div class = “box box3”>three</div> <div class = “box box4”>four</div> <div class = “box box5”>five</div> <div class = “box box6”>six</div> </div> </body> </html> It will produce the following result − wrap-reverse On passing the value wrap-reverse to the property flex-wrap, the elements of the container are arranged horizontally from left to right as shown below. The following example demonstrates the result of passing the value wrap-reverse to the flex-wrap property. Here, we are creating six boxes with different colors with the flex-direction value row. Live Demo <!doctype html> <html lang = “en”> <style> .box1{background:green;} .box2{background:blue;} .box3{background:red;} .box4{background:magenta;} .box5{background:yellow;} .box6{background:pink;} .box{ font-size:35px; padding:15px; width:100px; } .container{ display:flex; border:3px solid black; flex-direction:row; flex-wrap:wrap-reverse; } </style> <body> <div class = “container”> <div class = “box box1”>One</div> <div class = “box box2”>two</div> <div class = “box box3”>three</div> <div class = “box box4”>four</div> <div class = “box box5”>five</div> <div class = “box box6”>six</div> </div> </body> </html> It will produce the following result − wrap (column) On passing the value wrap to the property flex-wrap and the value column to the property flex-direction, the elements of the container are arranged horizontally from left to right as shown below. The following example demonstrates the result of passing the value wrap to the flex-wrap property. Here, we are creating six boxes with different colors with the flex-direction value column. Live Demo <!doctype html> <html lang = “en”> <style> .box1{background:green;} .box2{background:blue;} .box3{background:red;} .box4{background:magenta;} .box5{background:yellow;} .box6{background:pink;} .box{ font-size:35px; padding:15px; width:100px; } .container{ display:flex; border:3px solid black; flex-direction:column; flex-wrap:wrap; height:100vh; } </style> <body> <div class = “container”> <div class = “box box1”>One</div> <div class = “box box2”>two</div> <div class = “box box3”>three</div> <div class = “box box4”>four</div> <div class = “box box5”>five</div> <div class = “box box6”>six</div> </div> </body> </html> It will produce the following result − wrap-reverse (column) On passing the value wrap-reverse to the property flex-wrap and the value column to the property flex-direction, the elements of the container are arranged horizontally from left to right as shown below. The following example demonstrates the result of passing the value wrap-reverse to the flex-wrap property. Here, we are creating six boxes with different colors and the with the flex-direction value column. Live Demo <!doctype html> <html lang = “en”> <style> .box1{background:green;} .box2{background:blue;} .box3{background:red;} .box4{background:magenta;} .box5{background:yellow;} .box6{background:pink;} .box{ font-size:35px; padding:15px; width:100px; } .container{ display:flex; border:3px solid black; flex-direction:column; flex-wrap:wrap-reverse; height:100vh; } </style> <body> <div class = “container”> <div class = “box box1”>One</div> <div class = “box box2”>two</div> <div class = “box box3”>three</div> <div class = “box box4”>four</div> <div class = “box box5”>five</div> <div class = “box box6″>six</div> </div> </body> </html> It will produce the following result − Print Page Previous Next Advertisements ”;
Category: flexbox
Flexbox – Flexibility
Flexbox – Flexibility ”; Previous Next flex-basis We use the flex-basis property to define the default size of the flex-item before the space is distributed. The following example demonstrates the usage of the flex-basis property. Here we are creating 3 colored boxes and fixing their size to 150 px. Live Demo <!doctype html> <html lang = “en”> <style> .box{ font-size:15px; padding:15px; } .box1{background:green; flex-basis:150px; } .box2{background:blue; flex-basis:150px;} .box3{background:red; flex-basis:150px;} .container{ display:flex; height:100vh; align-items:flex-start; } </style> <body> <div class = “container”> <div class = “box box1”>One</div> <div class = “box box2”>two</div> <div class = “box box3”>three</div> </div> </body> </html> It will produce the following result − flex-grow We use the flex-grow property to set the flex-grow factor. In case of excess space in the container, it specifies how much a particular flex-item should grow. Live Demo <!doctype html> <html lang = “en”> <style> .box{ font-size:15px; padding:15px; } .box1{background:green; flex-grow:10; flex-basis:100px; } .box2{background:blue; flex-grow:1; flex-basis:100px; } .box3{background:red; flex-grow:1; flex-basis:100px; } .container{ display:flex; height:100vh; align-items:flex-start; } </style> <body> <div class = “container”> <div class = “box box1”>One</div> <div class = “box box2”>two</div> <div class = “box box3”>three</div> </div> </body> </html> It will produce the following result − flex-shrink We use the flex-shrink property is used to set the flex shrink-factor. In case there is not enough space in the container, it specifies how much a flex-item should shrink. Live Demo <!doctype html> <html lang = “en”> <style> .box{ font-size:15px; padding:15px; } .box1{background:green; flex-basis:200px; flex-shrink:10} .box2{background:blue; flex-basis:200px; flex-shrink:1} .box3{background:red; flex-basis:200px; flex-shrink:1} .container{ display:flex; height:100vh; align-items:flex-start; } </style> <body> <div class = “container”> <div class = “box box1”>One</div> <div class = “box box2”>two</div> <div class = “box box3″>three</div> </div> </body> </html> It will produce the following result − flex There is a shorthand to set values to all these three properties at once; it is called flex. Using this property, you can set values to flex-grow, flex-shrink, and flex-basis values at once. Here is the syntax of this property. .item { flex: none | [ <”flex-grow”> <”flex-shrink”>? || <”flex-basis”> ] } Print Page Previous Next Advertisements ”;
Flexbox – Overview
Flexbox – Overview ”; Previous Next Cascading Style Sheets (CSS) is a simple design language intended to simplify the process of making web pages presentable. CSS handles the look and feel part of a web page. Using CSS, you can control the color of the text, the style of fonts, the spacing between paragraphs, how columns are sized and laid out, what background images or colors are used, layout designs, variations in display for different devices and screen sizes as well as a variety of other effects. To determine the position and dimensions of the boxes, in CSS, you can use one of the layout modes available − The block layout − This mode is used in laying out documents. The inline layout − This mode is used in laying out text. The table layout − This mode is used in laying out tables. The table layout − This mode is used in positioning the elements. All these modes are used to align specific elements like documents, text, tables, etc., however, none of these provides a complete solution to lay out complex websites. Initially this is used to be done using a combination of floated elements, positioned elements, and table layout (often). But floats only allow to horizontally position the boxes. What is Flexbox? In addition to the above-mentioned modes, CSS3 provides another layout mode Flexible Box, commonly called as Flexbox. Using this mode, you can easily create layouts for complex applications and web pages. Unlike floats, Flexbox layout gives complete control over the direction, alignment, order, size of the boxes. Features of Flexbox Following are the notable features of Flexbox layout − Direction − You can arrange the items on a web page in any direction such as left to right, right to left, top to bottom, and bottom to top. Order − Using Flexbox, you can rearrange the order of the contents of a web page. Wrap − In case of inconsistent space for the contents of a web page (in single line), you can wrap them to multiple lines (both horizontally) and vertically. Alignment − Using Flexbox, you can align the contents of the webpage with respect to their container. Resize − Using Flexbox, you can increase or decrease the size of the items in the page to fit in available space. Supporting browsers Following are the browsers that support Flexbox. Chrome 29+ Firefox 28+ Internet Explorer 11+ Opera 17+ Safari 6.1+ Android 4.4+ iOS 7.1+ Print Page Previous Next Advertisements ”;
Flexbox – Flex-Order
Flexbox – Flex-Order ”; Previous Next The flex-order property is used to define the order of the flexbox item. The following example demonstrates the order property. Here we are creating six colored boxes with the labels one, two, three, four, five, six, arranged in the same order, and we are reordering them in the order one, two, five, six, three, four, using the flex-order property. Live Demo <!doctype html> <html lang = “en”> <style> .box{ font-size:35px; padding:15px; } .box1{background:green;} .box2{background:blue;} .box3{background:red; order:1} .box4{background:magenta; order:2} .box5{background:yellow;} .box6{background:pink;} .container{ display:inline-flex; border:3px solid black; flex-direction:rows; flex-wrap:wrap; } </style> <body> <div class = “container”> <div class = “box box1”>One</div> <div class = “box box2”>two</div> <div class = “box box3”>three</div> <div class = “box box4”>four</div> <div class = “box box5”>five</div> <div class = “box box6”>six</div> </div> </body> </html> It will produce the following result − – ve ordering You can also assign –ve values to the order as shown below. Live Demo <!doctype html> <html lang = “en”> <style> .box{ font-size:35px; padding:15px; } .box1{background:green;} .box2{background:blue;} .box3{background:red; order:-1} .box4{background:magenta; order:-2} .box5{background:yellow;} .box6{background:pink;} .container{ display:inline-flex; border:3px solid black; flex-direction:row; flex-wrap:wrap; } </style> <body> <div class = “container”> <div class = “box box1”>One</div> <div class = “box box2”>two</div> <div class = “box box3”>three</div> <div class = “box box4”>four</div> <div class = “box box5”>five</div> <div class = “box box6″>six</div> </div> </body> </html> It will produce the following result − Print Page Previous Next Advertisements ”;
Flexbox – Discussion
Discuss Flexbox ”; Previous Next Flexbox (flexible box) is a layout mode of CSS3. Using this mode, you can easily create layouts for complex applications and web pages. Flexbox layout gives complete control over the direction, alignment, order, size of the boxes. In this tutorial, we are going to learn how to use the various features available in Flexbox. Print Page Previous Next Advertisements ”;
Flexbox – Align Self
Flexbox – Align Self ”; Previous Next This property is similar to align-items, but here, it is applied to individual flex items. Usage − align-self: auto | flex-start | flex-end | center | baseline | stretch; This property accepts the following values − flex-start − The flex item will be aligned vertically at the top of the container. flex-end − The flex item will be aligned vertically at the bottom of the container. flex-center − The flex item will be aligned vertically at the center of the container. Stretch − The flex item will be aligned vertically such that it fills up the whole vertical space of the container. baseline − The flex item will be aligned at the base line of the cross axis. flex-start On passing this value to the property align-self, a particular flex-item will be aligned vertically at the top of the container. The following example demonstrates the result of passing the value flex-start to the align-self property. Live Demo <!doctype html> <html lang = “en”> <style> .box1{background:green;} .box2{background:blue;} .box3{background:red;} .box4{background:magenta; align-self:start;} .box5{background:yellow;} .box6{background:pink;} .box{ font-size:35px; padding:15px; } .container{ display:flex; height:100vh; border:3px solid black; align-items:flex-start; } </style> <body> <div class = “container”> <div class = “box box1”>One</div> <div class = “box box2”>two</div> <div class = “box box3”>three</div> <div class = “box box4”>four</div> <div class = “box box5”>five</div> <div class = “box box6”>six</div> </div> </body> </html> It will produce the following result − flex-end On passing this value to the property align-self, a particular flex-item will be aligned vertically at the bottom of the container. The following example demonstrates the result of passing the value flex-end to the align-self property. Live Demo <!doctype html> <html lang = “en”> <style> .box1{background:green;} .box2{background:blue;} .box3{background:red;} .box4{background:magenta; align-self:flex-end;} .box5{background:yellow;} .box6{background:pink;} .box{ font-size:35px; padding:15px; } .container{ display:flex; height:100vh; border:3px solid black; align-items:flex-start; } </style> <body> <div class = “container”> <div class = “box box1”>One</div> <div class = “box box2”>two</div> <div class = “box box3”>three</div> <div class = “box box4”>four</div> <div class = “box box5”>five</div> <div class = “box box6”>six</div> </div> </body> </html> It will produce the following result − center On passing the value center to the property align-self, a particular flex-item will be aligned vertically at the center of the container. The following example demonstrates the result of passing the value center to the align-self property. Live Demo <!doctype html> <html lang = “en”> <style> .box1{background:green;} .box2{background:blue;} .box3{background:red;} .box4{background:magenta; align-self:center;} .box5{background:yellow;} .box6{background:pink;} .box{ font-size:35px; padding:15px; } .container{ display:flex; height:100vh; border:3px solid black; align-items:flex-start; } </style> <body> <div class = “container”> <div class = “box box1”>One</div> <div class = “box box2”>two</div> <div class = “box box3”>three</div> <div class = “box box4”>four</div> <div class = “box box5”>five</div> <div class = “box box6”>six</div> </div> </body> </html> It will produce the following result − stretch On passing this value to the property align-self, a particular flex item it will be aligned vertically such that it fills up the whole vertical space of the container. The following example demonstrates the result of passing the value stretch to the align-self property. Live Demo <!doctype html> <html lang = “en”> <style> .box1{background:green;} .box2{background:blue;} .box3{background:red;} .box4{background:magenta; align-self:stretch;} .box5{background:yellow;} .box6{background:pink;} .box{ font-size:35px; padding:15px; } .container{ display:flex; height:100vh; border:3px solid black; align-items:flex-start; } </style> <body> <div class = “container”> <div class = “box box1”>One</div> <div class = “box box2”>two</div> <div class = “box box3”>three</div> <div class = “box box4”>four</div> <div class = “box box5”>five</div> <div class = “box box6″>six</div> </div> </body> </html> It will produce the following result − Print Page Previous Next Advertisements ”;
Flexbox – Flex Containers
Flexbox – Flex Containers ”; Previous Next To use Flexbox in your application, you need to create/define a flex container using the display property. Usage − display: flex | inline-flex This property accepts two values flex − Generates a block level flex container. inline-flex − Generates an inline flex container box. Now, we will see how to use the display property with examples. Flex On passing this value to the display property, a block level flex container will be created. It occupies the full width of the parent container (browser). The following example demonstrates how to create a block level flex container. Here, we are creating six boxes with different colors and we have used the flex container to hold them. Live Demo <!doctype html> <html lang = “en”> <style> .box1{background:green;} .box2{background:blue;} .box3{background:red;} .box4{background:magenta;} .box5{background:yellow;} .box6{background:pink;} .container{ display:flex; } .box{ font-size:35px; padding:15px; } </style> <body> <div class = “container”> <div class = “box box1”>One</div> <div class = “box box2”>two</div> <div class = “box box3”>three</div> <div class = “box box4”>four</div> <div class = “box box5”>five</div> <div class = “box box6”>six</div> </div> </body> </html> It will produce the following result − Since we have given the value flex to the display property, the container uses the width of the container (browser). You can observe this by adding a border to the container as shown below. .container { display:inline-flex; border:3px solid black; } It will produce the following result − Inline flex On passing this value to the display property, an inline level flex container will be created. It just takes the place required for the content. The following example demonstrates how to create an inline flex container. Here, we are creating six boxes with different colors and we have used the inline-flex container to hold them. Live Demo <!doctype html> <html lang = “en”> <style> .box1{background:green;} .box2{background:blue;} .box3{background:red;} .box4{background:magenta;} .box5{background:yellow;} .box6{background:pink;} .container{ display:inline-flex; border:3px solid black; } .box{ font-size:35px; padding:15px; } </style> <body> <div class = “container”> <div class = “box box1”>One</div> <div class = “box box2”>two</div> <div class = “box box3”>three</div> <div class = “box box4”>four</div> <div class = “box box5”>five</div> <div class = “box box6″>six</div> </div> </body> </html> It will produce the following result − Since we have used an inline flex container, it just took the space that is required to wrap its elements. Print Page Previous Next Advertisements ”;
Flexbox – Align Content
Flexbox – Align Content ”; Previous Next In case the flex-container has multiple lines (when, flex-wrap: wrap), the align-content property defines the alignment of each line within the container. Usage − align-content: flex-start | flex-end | center | space-between | space-around | stretch; This property accepts the following values − stretch − The lines in the content will stretch to fill up the remaining space. flex-start − All the lines in the content are packed at the start of the container. flex-end − All the lines in the content are packed at the end of the container. center − All the lines in the content are packed at the center of the container. space-between − The extra space is distributed between the lines evenly. space-around − The extra space is distributed between the lines evenly with equal space around each line (including the first and last lines) center On passing this value to the property align-content, all the lines are packed at the center of the container. The following example demonstrates the result of passing the value center to the align-content property. Live Demo <!doctype html> <html lang = “en”> <style> .box1{background:green;} .box2{background:blue;} .box3{background:red;} .box4{background:magenta;} .box5{background:yellow;} .box6{background:pink;} .box{ font-size:25px; padding:15px; width:43%; } .container{ display:flex; height:100vh; flex-wrap:wrap; align-content:center; } </style> <body> <div class = “container”> <div class = “box box1”>One</div> <div class = “box box2”>two</div> <div class = “box box3”>three</div> <div class = “box box4”>four</div> <div class = “box box5”>five</div> <div class = “box box6”>six</div> </div> </body> </html> It will produce the following result − flex-start On passing this value to the property align-content, all the lines are packed at the start of the container. The following example demonstrates the result of passing the value flex-start to the align-content property. Live Demo <!doctype html> <html lang = “en”> <style> .box1{background:green;} .box2{background:blue;} .box3{background:red;} .box4{background:magenta;} .box5{background:yellow;} .box6{background:pink;} .box{ font-size:25px; padding:15px; width:40%; } .container{ display:flex; height:100vh; flex-wrap:wrap; align-content:flex-start; } </style> <body> <div class = “container”> <div class = “box box1”>One</div> <div class = “box box2”>two</div> <div class = “box box3”>three</div> <div class = “box box4”>four</div> <div class = “box box5”>five</div> <div class = “box box6”>six</div> </div> </body> </html> It will produce the following result − flex-end On passing this value to the property align-content, all the lines are packed at the end of the container. The following example demonstrates the result of passing the value flex-end to the align-content property. Live Demo <!doctype html> <html lang = “en”> <style> .box1{background:green;} .box2{background:blue;} .box3{background:red;} .box4{background:magenta;} .box5{background:yellow;} .box6{background:pink;} .box{ font-size:25px; padding:15px; width:40%; } .container{ display:flex; height:100vh; flex-wrap:wrap; align-content:flex-end; } </style> <body> <div class = “container”> <div class = “box box1”>One</div> <div class = “box box2”>two</div> <div class = “box box3”>three</div> <div class = “box box4”>four</div> <div class = “box box5”>five</div> <div class = “box box6”>six</div> </div> </body> </html> It will produce the following result − stretch On passing this value to the property align-content, the lines will stretch to fill up the remaining space. The following example demonstrates the result of passing the value stretch to the align-content property. Live Demo <!doctype html> <html lang = “en”> <style> .box1{background:green;} .box2{background:blue;} .box3{background:red;} .box4{background:magenta;} .box5{background:yellow;} .box6{background:pink;} .box{ font-size:25px; padding:15px; width:40; } .container{ display:flex; height:100vh; flex-wrap:wrap; align-content:stretch; } </style> <body> <div class = “container”> <div class = “box box1”>One</div> <div class = “box box2”>two</div> <div class = “box box3”>three</div> <div class = “box box4”>four</div> <div class = “box box5”>five</div> <div class = “box box6”>six</div> </div> </body> </html> It will produce the following result − space-around On passing this value to the property align-content, the extra space is distributed between the lines evenly with equal space around each line (including the first and last lines). The following example demonstrates the result of passing the value space-around to the align-content property. Live Demo <!doctype html> <html lang = “en”> <style> .box1{background:green;} .box2{background:blue;} .box3{background:red;} .box4{background:magenta;} .box5{background:yellow;} .box6{background:pink;} .box{ font-size:25px; padding:15px; width:40%; } .container{ display:flex; height:100vh; flex-wrap:wrap; align-content:space-around; } </style> <body> <div class = “container”> <div class = “box box1”>One</div> <div class = “box box2”>two</div> <div class = “box box3”>three</div> <div class = “box box4”>four</div> <div class = “box box5”>five</div> <div class = “box box6”>six</div> </div> </body> </html> It will produce the following result − space-between On passing this value to the property align-content, the extra space is distributed between the lines evenly, where the first line will be at the top and the last line will be at the bottom of the container. The following example demonstrates the result of passing the value space-between to the align-content property. Live Demo <!doctype html> <html lang = “en”> <style> .box1{background:green;} .box2{background:blue;} .box3{background:red;} .box4{background:magenta;} .box5{background:yellow;} .box6{background:pink;} .box{ font-size:25px; padding:15px; width:40%; } .container{ display:flex; height:100vh; flex-wrap:wrap; align-content:space-between; } </style> <body> <div class = “container”> <div class = “box box1”>One</div> <div class = “box box2”>two</div> <div class = “box box3”>three</div> <div class = “box box4”>four</div> <div class = “box box5”>five</div> <div class = “box box6″>six</div> </div> </body> </html> It will produce the following result − Print Page Previous Next Advertisements ”;
Flexbox – Useful Resources
Flexbox – Useful Resources ”; Previous Next The following resources contain additional information on Flexbox. Please use them to get more in-depth knowledge on this topic. Useful Video Courses Complete CSS Flexbox course & real world website project 22 Lectures 2.5 hours DigiFisk (Programming Is Fun) More Detail CSS Bootcamp – Master CSS (Including CSS Grid/Flexbox) Most Popular 88 Lectures 11 hours Code And Create More Detail Mastering Tailwind Css With real world Projects 37 Lectures 5.5 hours Mead More Detail Learn to Code HTML & CSS for Responsive Real-World Websites 129 Lectures 11.5 hours Metla Sudha Sekhar More Detail HTML CSS JavaScript for Modern Web Developers Best Seller 198 Lectures 17.5 hours Metla Sudha Sekhar More Detail Front End Web Design UX, CSS, FLEXBOX & SASS Complete Course 139 Lectures 9.5 hours Manuel Estasio More Detail Print Page Previous Next Advertisements ”;
Flexbox – Home
Flexbox Tutorial PDF Version Quick Guide Resources Job Search Discussion Flexbox (flexible box) is a layout mode of CSS3. Using this mode, you can easily create layouts for complex applications and web pages. Flexbox layout gives complete control over the direction, alignment, order, size of the boxes. In this tutorial, we are going to learn how to use the various features available in Flexbox. Audience This tutorial has been prepared for beginners to make them understand the basics of Flexbox library. It will help the readers in aligning the contents of a webpage easily. Prerequisites For this tutorial, it is assumed that the readers have a prior knowledge of CSS and HTML Print Page Previous Next Advertisements ”;