align-items 属性定义项目在交叉轴上如何对齐。
语法:

.box {align-items: flex-start | flex-end | center | baseline | stretch;
}

属性值

align-items 属性有5个值,如下:

  • flex-start:交叉轴的起点对齐。
  • flex-end:交叉轴的终点对齐。
  • center:交叉轴的中点对齐。
  • baseline: 项目的第一行文字的基线对齐。
  • stretch(默认值):如果项目未设置高度或设为auto,将占满整个容器的高度。

flex-start

实例:

<!DOCTYPE html>
<html>
<head>
<style>
.container {width: 350px;height: 350px;border: 1px solid #c3c3c3;display: flex;display: -webkit-flex; /* Safari */align-items: flex-start;
}
.container div { width:50px; }
.container div:nth-of-type(1) {background-color:coral;height:50px;}
.container div:nth-of-type(2) {background-color:lightblue;height:250px;}
.container div:nth-of-type(3) {background-color:khaki;height:150px;}
.container div:nth-of-type(4) {background-color:pink;height:50px;}
.container div:nth-of-type(5) {background-color:lightgrey;height:100px;}</style>
</head>
<body><div class="container"><div>1</div><div>2</div><div>3</div><div>4</div><div>5</div>
</div><p><b>注意:</b> Internet Explorer 10 及更早版本浏览器不支持 flex-grow 属性。</p>
<p><b>注意:</b> Safari 6.1 及更新版本通过 -webkit-flex-grow 属性支持该属性。</p></body>
</html>

页面效果:

flex-end

实例:

  align-items: flex-end;

页面效果:

center

实例:

  align-items: center;

页面效果:

baseline

实例:

<!DOCTYPE html>
<html>
<head>
<style>
.container {width: 350px;height: 350px;border: 1px solid #c3c3c3;display: flex;display: -webkit-flex; /* Safari */align-items: baseline;
}
.container div { width:50px; }
.container div:nth-of-type(1) {background-color:coral;height:50px;font-size:42px;}
.container div:nth-of-type(2) {background-color:lightblue;height:250px;font-size:28px;}
.container div:nth-of-type(3) {background-color:khaki;height:150px;}
.container div:nth-of-type(4) {background-color:pink;height:200px;;font-size:14px;}
.container div:nth-of-type(5) {background-color:lightgrey;height:100px;}</style>
</head>
<body><div class="container"><div>1</div><div><p>111</p><p>222</p><p>333</p><p>444</p></div><div>3</div><div><p>111</p><p>222</p><p>333</p></div><div>5</div>
</div><p><b>注意:</b> Internet Explorer 10 及更早版本浏览器不支持 flex-grow 属性。</p>
<p><b>注意:</b> Safari 6.1 及更新版本通过 -webkit-flex-grow 属性支持该属性。</p></body>
</html>

页面效果:

可以看到,项目的第一行文字的基线是对齐的:

stretch

实例:

<!DOCTYPE html>
<html>
<head>
<style>
.container {width: 350px;height: 350px;border: 1px solid #c3c3c3;display: flex;display: -webkit-flex; /* Safari */align-items: stretch;
}
.container div { width:50px; }
.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;}</style>
</head>
<body><div class="container"><div>1</div><div>2</div><div>3</div><div>4</div><div>5</div>
</div><p><b>注意:</b> Internet Explorer 10 及更早版本浏览器不支持 flex-grow 属性。</p>
<p><b>注意:</b> Safari 6.1 及更新版本通过 -webkit-flex-grow 属性支持该属性。</p></body>
</html>

页面效果:

css flex布局 —— 容器属性 align-items相关推荐

  1. css flex布局 —— 容器属性 flex-wrap

    flex-wrap属性 默认情况下,项目都排在一条线(又称"轴线")上.flex-wrap属性定义,如果一条轴线排不下,如何换行. 语法 .box{flex-wrap: nowra ...

  2. css flex布局 —— 项目属性 flex-grow

    flex-grow 属性定义项目的放大比例,解决的问题是:在空间有多余时把多余空间分配给各个子元素. flex-grow 的值默认为 0,也就是说,如果存在剩余空间,也不放大. flex-grow 取 ...

  3. css flex布局 模型(CSS justify-content 属性) - 代码案例

    css flex布局 模型(CSS justify-content 属性) - 代码案例 效果图: . 代码如下: .father{display: -webkit-box;display: -ms- ...

  4. css布局方式_手把手教你CSS Flex布局「真香」

    作者:EcbJS 转发链接:https://blog.csdn.net/EcbJS/article/details/106466757 前言   之前做项目,关于布局方面没怎么深入研究过,好多页面都是 ...

  5. 前端css弹性布局各种属性

    前端css弹性布局各种属性 一.基本概念 Flexbox 是 flexible box 的简称(注:意思是"灵活的盒子容器")又叫弹性布局,是 CSS3 引入的新的布局模式.它决定 ...

  6. W3C推荐的新布局模式 【CSS Flex布局】详解

    本文目录 概述 属性 弹性容器的属性(父级) display flex-direction flex-wrap flex-flow justify-content align-items align- ...

  7. html flex自动换行,css flex布局超长自动换行的示例代码

    要创建一个 flex 容器,只需要将一个 display: flex 属性添加到一个元素上. 默认情况下,所有的直接子元素都被认为是 flex 项,并从左到右依次排列在一行中. 如果 flex 项的宽 ...

  8. html实现 左图右文_让CSS flex布局最后一行左对齐的N种方法

    作者:张鑫旭 https://www.zhangxinxu.com/wordpress/2019/08/css-flex-last-align/ 前言 小伙伴们是否还记得,之前小编也发布了几篇关于CS ...

  9. [css] flex布局的缺点有哪些?(除兼容性外)

    [css] flex布局的缺点有哪些?(除兼容性外) 无法直接定义列数(要使用百分比的方式实现) 个人简介 我是歌谣,欢迎和大家一起交流前后端知识.放弃很容易, 但坚持一定很酷.欢迎大家一起讨论 主目 ...

最新文章

  1. arnold如何设置鱼眼相机_华为相机实用技巧——如何调整相机设置?(2)
  2. 结构体和数组之间的映射关系
  3. python精进之路 -- open函数
  4. [watevrCTF 2019]Repyc [NPUCTF2020]BasicASM
  5. 转:Xcode下的GDB调试命令
  6. Linux 命令之 which -- 查找并显示给定命令的绝对路径(查找命令的位置/查询命令的位置/搜索命令的位置/查看命令的位置)
  7. 面试真题------hashmap与hashset
  8. [转]mysql_connect() 不支持 请检查 mysql 模块是否正确加载 解决
  9. java云之家发送信息_开发文档:考勤信息api - 云之家·开放平台
  10. (批处理)如何通过Python或批处理指令删除指定文件夹?
  11. 计算机应用总线带宽,带宽
  12. lwj_C#_集合stack栈和queue队列
  13. IIS:CS0016: 未能写入输出文件
  14. 360WiFi的服务器网站,360随身无线wifi怎么搭建web认证网页
  15. Unity系统Cube的法线
  16. python zipfile 压缩文件夹的方法
  17. 【初识C语言:编程小白与C语言say hello的正确打开方式(绘制草图阶段)】
  18. 为什么有的人职场上混得如鱼得水,有的人却混得狼狈不堪呀?
  19. 卡罗拉更换变速油教程
  20. 四年级计算机入门教案,四年级下册计算机教案

热门文章

  1. 银行数字化转型开年布局,金融级架构面临的6大挑战和应对思路
  2. POJ2584_T-Shirt Gumbo(二分图多重最大匹配/最大流)
  3. 电气CAD制图软件中如何进行开关连接?
  4. php com word 设置字体和字号
  5. 【HTML】实现地址选择联动
  6. GCP: IAM的使用
  7. C# System.Diagnostics.Stopwatch 记录程序执行时间
  8. DLT645编码解码基本类
  9. VS下编译 缺少unistd.h的解决方法
  10. MATLAB 单双引号