CSS Flexbox

CSS Tutorial

CSS Advanced

CSS Responsive

CSS Grid

CSS Flexbox

CSS Flexbox Layout Module

Before the Flexbox Layout module, there were four layout modes:

  • Block, for sections in a webpage.
  • Inline, for text.
  • Table, for two-dimensional table data.
  • Positioned, for explicit position of an element.

The Flexible Box Layout Module, are easy to design flexible responsive layout structure without making use of float or positioning.

Flexbox Elements

To use the Flexbox model, firstly, specify a flex container.

HTML
				
					<h1>Create a Flex Container</h1>
<div class="flex-container">
  <div>1</div>
  <div>2</div>
  <div>3</div>  
</div>
<p>A Flexible Layout must have a parent element with the <em>display</em> property set to <em>flex</em>.</p>
<p>Direct child elements(s) of the flexible container automatically becomes flexible items.</p>
				
			
CSS
				
					.flex-container {
  display: flex;
  background-color: DodgerBlue;
}

.flex-container > div {
  background-color: #f1f1f1;
  margin: 10px;
  padding: 20px;
  font-size: 30px;
}
				
			

Output

Create a Flex Container
1
2
3

A Flexible Layout must have a parent element with the display property set to flex.

Direct child elements(s) of the flexible container automatically becomes flexible items.