Knock-knock Flexbox

Stanislau Zibovich, EPAM

~9 years

~1 year

CSS
~2 years

"Layout is hard!"

Knock Knock Flexbox!

Оси

Главная

Поперечная

Что под капотом?

			<div class="container">
			    <div class="item">x</div>
			    <div class="item">x</div>
			    <div class="item">x</div>
			    <div class="item">x</div>
			</div>
		
			.container {
			    overflow:hidden;
			    height:640px;
			    }
			    .container .item {
			        float:left;
			        }
		
x
x
x
x

Flexbox.On()

			
			.container {
			    display:flex;
			    }
		
x
x
x
x
x
x
x
x

Дайте мне точку опоры

			
			.container {
			    display:flex;
			    flex-direction:row; /* по умолчанию */
			                  :row-reverse;
			    }
		
x
x
x
x

Повернем ось

			
			.container {
			    display:flex;
			    flex-direction:column;
			    }
		
x
x
x
x

Дайте мне точку опоры

			
			.container {
			    display:flex;
			    flex-direction:column-reverse;
			    }
		
x
x
x
x
x
x
x
x

Start/End

Повыравниваем

По ширине

			
			.container {
			    justify-content:flex-start; /* по умолчанию */
			                    center;
			                    flex-end;
			    }
		
×
×
×
×

Равномерно:

			
			.container {
			    justify-content:space-between;
			                    space-around;
			    }
		
×
×
×
×

По высоте

			
			.container {
			    align-items:flex-start; /* по умолчанию */
			                flex-end;
			                center;
			    }
		
×
×
×
×
×
×
×
×

Персонально

			
			.container .item:nth-child(1) {
			    align-self:flex-start;
			    }
			.container .item:nth-child(4) {
			    align-self:flex-end;
			    }
		
×
×
×
×
OMG, I’m centered

Как:

			
			.container {
			    display:flex;
			    }
		
	
			.item {
			    margin:auto;
			    }
		

Flex

×
×
×
×

Порастягиваем

			.container .item {
			    flex-grow:1;
			    }
		
×
×
×
×
×
×
×
×
×
×

Персонально

			.container div {
			    flex-grow:1;
			    }
			.container .item:nth-child(1) {
			    flex-grow:4;
			    }
		
×
×
×
×
×
×
×
×

Посжимаем

			
			.container .item:nth-child(1) {
			    flex-shrink:4;
			    }
		
×
×
×
×
×
×
×
×

Похомячим

			.container .item {
			    flex-grow:1;
			    }
			.container .item:nth-child(1) {
			    flex-basis:250px;
			    }
		
×
×
×
×

Попереставляем

first
second
third
last.

Поменяем порядок:

			
			.container .item:nth-child(2) {
			    order:1;
			    }
		
first
second
third
last.
first
second
third
last.

Многострочный Flexbox

first
second
third
bender
smth
anything
google
музыка скачать
купить авто
Rolling Scopes
Facebook
presentation
pink
last.
first
second
third
bender
smth
anything
google
музыка скачать
купить авто
Rolling Scopes
Facebook
presentation
pink
last.

Попереносим

			.container {
			    display:flex;
			    flex-wrap:nowrap; /* по умолчанию */
			             :wrap;
			    }
		
first
second
third
bender
smth
anything
google
музыка скачать
купить авто
Rolling Scopes
Facebook
presentation
pink
last.

А что если... все было наоборот?

			.container {
			    display:flex;
			    flex-wrap:wrap-reverse;
			    }
		
first
second
third
bender
smth
anything
google
музыка скачать
купить авто
Rolling Scopes
Facebook
presentation
pink
last.
first
second
third
bender
smth
anything
google
музыка скачать
купить авто
Rolling Scopes
Facebook
presentation
pink
last.

Поперек

			.container {
			    display:flex;
			    align-content:stretch; /* по умолчанию */
			                 :center;
			    }
		

Только для многострочных блоков!

first
second
third
bender
smth
anything
google
музыка скачать
купить авто
Rolling Scopes
Facebook
presentation
pink
last.

Поперечная

first
second
third
bender
smth
anything
google
музыка скачать
купить авто
Rolling Scopes
Facebook
presentation
pink
last.

79.97%

09 ‣  11 ‣  12

09 ‣  11 ‣  12

09 ‣  11 ‣  12

09 ‣  11 ‣  12

09 ‣  11 ‣  12

Flexbox.On()

		
			E {	
			    display: -webkit-box;
			    display: -moz-box;
			    display: -ms-flexbox;
			    display: -webkit-flex;
			    display: flex;
			    }
		

Flexbox.Reverse()

		
			E {	
			        -webkit-box-orient:vertical;
			     -webkit-box-direction:reverse;
			           -moz-box-orient:vertical;
			        -moz-box-direction:reverse;
			        -ms-flex-direction:column-reverse;
			    -webkit-flex-direction:column-reverse;
			            flex-direction:column-reverse;
			    }
		

BackToBasic.Native()

		
			E {	
			    display: table;
			    }
		
		
			E .item {	
			    display: table-cell;
			    width: 50%;
			    }
		

Что почитать?

Questions?

Powered by Shower