目录

Flexbox - 对齐自我( Align Self)

此属性类似于align-items ,但在此处,它适用于各个flex项。

Usage -

align-self: auto | flex-start | flex-end | center | baseline | stretch;

此属性接受以下值 -

  • flex-start - 弹性项目将在容器顶部垂直对齐。

  • flex-end - flex项目将在容器底部垂直对齐。

  • flex-center - 弹性项目将在容器的中心垂直对齐。

  • Stretch - 柔性项目将垂直对齐,以便填充容器的整个垂直空间。

  • baseline - 弹性项目将在横轴的baseline处对齐。

flex-start

将此值传递给属性align-self时,特定的flex项将在容器顶部垂直对齐。

Flex对齐自我启动

以下示例演示将值flex-start传递给align-self属性的结果。

<!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>

它会产生以下结果 -

新页面打开

flex-end

将此值传递给属性align-self ,特定的flex项将在容器的底部垂直对齐。

Flex对齐自我结束

以下示例演示将值flex-end传递给align-self属性的结果。

<!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>

它会产生以下结果 -

新页面打开

center

在将值center传递给属性align-self ,特定的flex项将在容器的中心垂直对齐。

Flex Align Self Center

以下示例演示将值center传递给align-self属性的结果。

<!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>

它会产生以下结果 -

新页面打开

stretch

在将此值传递给属性align-self ,特定的弹性项目将垂直对齐,以便填充容器的整个垂直空间。

Flex Align Self Stretch

以下示例演示将值stretch传递给align-self属性的结果。

<!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>

它会产生以下结果 -

新页面打开
↑回到顶部↑
WIKI教程 @2018