DEV Community

jason ho
jason ho

Posted on

TIL 4.5

Flexbox

div.container {
  display: flex;
}
Enter fullscreen mode Exit fullscreen mode

Image description

Inline-flex:

display: inline-flex;
Enter fullscreen mode Exit fullscreen mode

Image description

Justify-content:

.container {
  display: flex;
  justify-content: flex-end;
}
Enter fullscreen mode Exit fullscreen mode

flex-start
flex-end
center
space-around
space-between

Image description

Image description

Align-items:

.container {
  align-items: baseline;
}
Enter fullscreen mode Exit fullscreen mode

Image description

Image description

Flex-grow:

.center {
  width: 100px;
  flex-grow: 2;
}
Enter fullscreen mode Exit fullscreen mode

Image description

Flex-shrink:

Pretty much the opposite of grow.

Flex-basis:

Another way of specifying the width of a flex item is with the flex-basis property. flex-basis allows us to specify the width of an item before it stretches or shrinks.

  flex-basis: 150px;
Enter fullscreen mode Exit fullscreen mode

Flex shorthand :

Flex: grow shrink basis

.big {
  flex-grow: 2;
  flex-shrink: 1;
  flex-basis: 150px;
}

.small {
  flex-grow: 1;
  flex-shrink: 2;
  flex-basis: 100px;
}
Enter fullscreen mode Exit fullscreen mode

vs

.big {
  flex: 2 1 150px;
}

.small {
  flex: 1 2 100px;
}

Enter fullscreen mode Exit fullscreen mode

Flex-wrap:

wrap
wrap-reverse
nowrap

.container {
  display: inline-flex;
  flex-wrap: wrap;
  width: 250px;
}
Enter fullscreen mode Exit fullscreen mode

Flex-direction:

Image description

Image description

Image description

Top comments (0)