常用的flex布局介绍(水平居中和垂直居中)

常用的flex布局介绍

    • 1.flex-direction
          • flex-direction:row;(==默认==)
          • flex-direction:row-reverse;
          • flex-direction:column;
          • flex-direction:column-reserve;
    • 2.flex-wrap
          • flex-wrap:nowrap;(==不换行,默认==)
          • flex-wrap:wrap;(==换行==)
          • flex-wrap:wrap-reverse;(==换行==)
        • ==flex-flow:row nowrap;(默认,flex-direction和flex-wrap的简写)==
    • 3.justify-content
          • justify-content:center;(==水平居中==)
          • justify-content:space-between;(==div之间间隔相等==)
          • justify-content:space-around;(==div两侧间隔相等==)
    • 4.justify-content
          • align-items: center;(==垂直居中==)

<div class="outer_box">
  <div>1div>
  <div>2div>
  <div>3div>
  <div>4div>
  <div>5div>
  <div>6div>
div>

1.flex-direction

flex-direction:row;(默认)
.outer_box {
  display:flex;
  flex-direction:row;
  width:800px;
  border: 1px solid #000;
}

.outer_box div {
  width: 100px;
  height: 100px;
  background: skyblue;
  border:1px solid #000;
}

常用的flex布局介绍(水平居中和垂直居中)_第1张图片

flex-direction:row-reverse;
.outer_box {
  display:flex;
  flex-direction:row-reverse;
  width:800px;
  border: 1px solid #000;
}

.outer_box div {
  width: 100px;
  height: 100px;
  background: skyblue;
  border:1px solid #000;
}

常用的flex布局介绍(水平居中和垂直居中)_第2张图片

flex-direction:column;
.outer_box {
  display: flex;
  flex-direction:column;
  height: 800px;
  border: 1px solid #000;
}

.outer_box div {
  width: 100px;
  height: 100px;
  background: skyblue;
  border: 1px solid #000;
}

常用的flex布局介绍(水平居中和垂直居中)_第3张图片

flex-direction:column-reserve;
.outer_box {
  display: flex;
  flex-direction:column-reverse;
  height: 800px;
  border: 1px solid #000;
}

.outer_box div {
  width: 100px;
  height: 100px;
  background: skyblue;
  border: 1px solid #000;
}

常用的flex布局介绍(水平居中和垂直居中)_第4张图片

2.flex-wrap

flex-wrap:nowrap;(不换行,默认)

如果父盒子过小,装不下子盒子,则子盒子宽度变小

.outer_box {
  display:flex;
  flex-wrap:nowrap;
  width: 450px;
  border: 1px solid #000;
}

.outer_box div {
  width: 100px;
  height: 100px;
  background: skyblue;
  border:1px solid #000;
}

常用的flex布局介绍(水平居中和垂直居中)_第5张图片

flex-wrap:wrap;(换行)
.outer_box {
  display:flex;
  flex-wrap:wrap;
  width: 450px;
  border: 1px solid #000;
}

.outer_box div {
  width: 100px;
  height: 100px;
  background: skyblue;
  border:1px solid #000;
}

常用的flex布局介绍(水平居中和垂直居中)_第6张图片

flex-wrap:wrap-reverse;(换行)
.outer_box {
  display:flex;
  flex-wrap:wrap-reverse;
  width: 450px;
  border: 1px solid #000;
}

.outer_box div {
  width: 100px;
  height: 100px;
  background: skyblue;
  border:1px solid #000;
}

常用的flex布局介绍(水平居中和垂直居中)_第7张图片

flex-flow:row nowrap;(默认,flex-direction和flex-wrap的简写)

3.justify-content

justify-content:center;(水平居中)
.outer_box {
  display:flex;
  justify-content:center;
  width: 1000px;
  border: 1px solid #000;
}

.outer_box div {
  width: 100px;
  height: 100px;
  background: skyblue;
  border:1px solid #000;
}

在这里插入图片描述

justify-content:space-between;(div之间间隔相等
.outer_box {
  display:flex;
  justify-content:space-between;
  width:1000px;
  border:1px solid #000;
}
}

.outer_box div {
  width: 100px;
  height: 100px;
  background: skyblue;
  border:1px solid #000;
}

在这里插入图片描述

justify-content:space-around;(div两侧间隔相等
.outer_box {
  display:flex;
  justify-content:space-around;
  width:200px;
  height: 800px;
  border: 1px solid #000;
}

.outer_box div {
  width: 100px;
  height: 100px;
  background: skyblue;
  border:1px solid #000;
}

在这里插入图片描述

4.justify-content

align-items: center;(垂直居中)
.outer_box {
  display: flex;
  align-items: center;
  height:200px;
  border:1px solid #000;
}

.outer_box div {
  width: 100px;
  height: 100px;
  background: skyblue;
  border: 1px solid #000;
}

常用的flex布局介绍(水平居中和垂直居中)_第8张图片

你可能感兴趣的:(flex常用布局,水平居中,垂直居中)