• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

css flex布局 —— 容器属性 align-content

武飞扬头像
*且听风吟
帮助1

align-content 属性定义了多根轴线的对齐方式。

如果项目只有一根轴线,该属性不起作用(如果只有一根轴线, align-content 几乎等同于 align-items)。

容器属性 align-content 生效的条件是:必须显式的设置布局方向。

如果布局方向为横向主轴:flex-direction: row;
1、此时 align-content 的变化体现在竖直方向;
2、如果要让 align-content: stretch;生效,这个时候应该去掉子项的高度或者设置子项的高度为 auto

如果布局方向为纵向交叉轴:flex-direction: column;
1、此时 align-content 的变化体现在水平方向
2、如果要让 align-content: stretch;生效,这个时候应该去掉子项的宽度或者设置子项的宽度为 auto

语法

align-content 语法格式如下:

.container {
    align-content: stretch (默认值) | center | flex-start | flex-end | space-between | space-around;
}

属性

  • align-content 属性有取6个值,如下: flex-start:与交叉轴的起点对齐。
  • flex-end:与交叉轴的终点对齐。 center:与交叉轴的中点对齐。
  • space-between:与交叉轴两端对齐,轴线之间的间隔平均分布。
  • space-around:每根轴线两侧的间隔都相等。所以,轴线之间的间隔比轴线与边框的间隔大一倍。
  • stretch(默认值):轴线占满整个交叉轴。

flex-start

实例:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <style>
    .container {
      display: flex;
      margin: 0px auto;
      width: 900px;
      height: 300px;
      background-color: #e6e6e6;
      flex-wrap: wrap;
      align-content: flex-start;
    }
    .item {
      width: 250px;
      height: 50px;
      margin-left: 10px;
      margin-top: 10px;
    }
    .container div:nth-of-type(1) {background-color:coral;}
    .container div:nth-of-type(2) {background-color:lightblue;}
    .container div:nth-of-type(3) {background-color:khaki;}
    .container div:nth-of-type(4) {background-color:pink;}
    .container div:nth-of-type(5) {background-color:lightgrey;}
    .container div:nth-of-type(6) {background-color:orange;}
    .container div:nth-of-type(7) {background-color:purple;}
  </style>
</head>
<body>
  <div class="container">
    <div class="item">1</div>
    <div class="item">2</div>
    <div class="item">3</div>
    <div class="item">4</div>
    <div class="item">5</div>
    <div class="item">6</div>
    <div class="item">7</div>
  </div>
</body>
</html>
学新通

页面效果:
学新通

flex-end

实例:

      align-content: flex-end;

页面效果:
学新通

center

实例:

      align-content: center;

页面效果:
学新通

space-between

实例:

      align-content: space-between;

页面效果:
学新通

space-around

实例:

      align-content: space-around;

页面效果:
学新通

stretch

实例:

      align-content: stretch;

页面效果:
学新通

这篇好文章是转载于:编程之路

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 编程之路
  • 本文地址: /boutique/detail/tanhhacejh
系列文章
更多 icon
同类精品
更多 icon
继续加载