非常教程

CSS参考手册

灵活的框布局 | Flexible Box Layout

对齐自身 | align-self

align-self 属性将当前弹性行的 flex 项与 "align-items" 值对齐。如果任何项目的横轴边距设置为auto,则align-self忽略。

该属性不适用于块级框或表单元格。

/* Keyword values */ 
align-self: auto; 
align-self: normal; 

/* Positional alignment */ 
align-self: center; /* Put the item around the center */ 
align-self: start; /* Put the item at the start */ 
align-self: end; /* Put the item at the end */ 
align-self: self-start; /* Align the item flush at the start */ 
align-self: self-end; /* Align the item flush at the end */ 
align-self: flex-start; /* Put the flex item at the start */ 
align-self: flex-end; /* Put the flex item at the end */ 
align-self: left; /* Put the item at the left */ 
align-self: right; /* Put the item at the right */ 

/* Baseline alignment */ 
align-self: baseline; 
align-self: first baseline; 
align-self: last baseline; 
align-self: stretch; /* Stretch 'auto'-sized items to fit the container */ 

/* Overflow alignment */ 
align-self: safe center; 
align-self: unsafe center; 

/* Global values */ 
align-self: inherit; 
align-self: initial; 
align-self: unset;

初始值

自动的

适用于

弹性项目,包括流入的伪元素

遗传

没有

媒体

视觉

计算值

auto在绝对定位的元素上计算自身,并在所有其他框上计算父对齐项的计算值(减去任何遗留关键字),或者在框没有父项时开始计算。它的行为取决于布局模型,如justify-self所描述的。否则指定的值。

动画类型

离散的

规范的顺序

形式语法定义的独特的非模糊顺序

语法

auto计算父级的align-items值。

normal这个关键字的效果取决于我们所在的布局模式:

  • 在绝对定位的布局中,关键字的行为类似于start取代绝对定位的盒子stretch所有其他绝对定位的箱子。
  • 在绝对定位布局的静态位置中,关键字表现为stretch.
  • 对于Flex项,关键字表现为stretch.
  • 对于网格项,此关键字将导致类似于stretch,但具有高宽比或内部大小的盒子除外,其行为方式如下start.
  • 该属性不适用于块级别框和表格单元格。

self-start将对齐的项目与横轴上对应项目起点的对齐容器的边缘对齐。

self-end将对齐的项目与横轴上对应于项目的端侧的对齐容器的边缘对齐。

flex-startFlex项目的交叉开始边缘边缘与线条的交叉起始边缘一起被刷新。

flex-endFlex项目的交叉边缘边缘与线条的交叉边缘齐平。

centerFlex项目的边距框在交叉轴线上居中。如果物品的交叉尺寸大于柔性容器,则它将在两个方向上均等地溢出。

baseline

first baseline

last baseline指定参与第一个或最后一个基线对齐:将框的第一个或最后一个基准集的对齐基线与其基准共享组中所有框的共享的第一个或最后一个基准集中的相应基线对齐。

第一个基线的回退对齐方式为start,最后一个基线为是end。stretch如果沿着横轴的物品的组合尺寸小于对齐容器的auto尺寸并且物品是大小的,则它的尺寸被同等地(不成比例地)增加,同时仍然遵守由max-height/ max-width(或者等同的功能)所施加的约束,以便所有auto尺寸的物品的组合尺寸正好沿横轴填充对齐容器。safe如果项目的大小溢出对齐容器,则对齐项目就像对齐模式一样对齐startunsafe无论物品和对齐容器的相对大小如何,给定的对齐值都是可以接受的。

形式语法

auto | flex-start | flex-end | center | baseline | stretch

示例

HTML

<section>
  <div>Item #1</div>
  <div>Item #2</div>
  <div>Item #3</div>
</section>

CSS

section {
  display: flex;
  align-items: center;
  height: 120px;
  background: beige;
}

div {
  height: 60px;
  background: cyan;
  margin: 5px;
}

div:nth-child(3) {
  align-self: flex-end;
  background: pink;
}

结果

规范

Specification

Status

Comment

CSS Box Alignment ModuleThe definition of 'align-self' in that specification.

Working Draft

Adds the first | last ? baseline, self-start, self-end, start, end, left, right, unsafe | safe values.

CSS Flexible Box Layout ModuleThe definition of 'align-self' in that specification.

Candidate Recommendation

Initial definition.

浏览器兼容性

Feature

Chrome

Edge

Firefox (Gecko)

Internet Explorer

Opera

Safari

Basic support

21.0-webkit 36.0

(Yes)

20.0 (20.0)1

11.0

12.10

No support

start, end

?

?

(Yes)

?

?

?

left, right

?

?

52.0 (52.0)3

?

?

?

baseline

?

?

(Yes)

?

?

?

first baseline, last baseline

?

?

52.0 (52.0)

?

?

?

stretch

?

?

52.0 (52.0)

?

?

?

Feature

Android

Chrome for Android

Edge

Firefox Mobile (Gecko)

IE Mobile

Opera Mobile

Safari Mobile

Basic support

?

?

(Yes)-webkit (Yes)

(Yes)

?

No support

12.10

No support

start, end

?

?

?

?

?

?

?

left, right

?

?

?

52.0 (52.0)3

?

?

?

baseline

?

?

?

(Yes)

?

?

?

first baseline, last baseline

?

?

?

52.0 (52.0)

?

?

?

stretch

?

?

?

52.0 (52.0)

?

?

?

CSS

层叠样式表( Cascading Style Sheets )是一种用来表现 HTML 或 XML 等文件样式的计算机语言。CSS 不仅可以静态地修饰网页,还可以配合各种脚本语言动态地对网页各元素进行格式化。

CSS目录

1.动画和转换 | Animations & Transitions
2.背景和边框 | Backgrounds & Borders
3.基本框模型 | Basic Box Model
4.基本用户界面 | Basic User Interface
5.框对齐 | Box Alignment
6. 级联和继承 | Cascading & Inheritance
7.颜色 | Color
8. 合成与混合 | Compositing & Blending
9.条件和规则 | Conditional Rules
10.计数器样式 | Counter Styles
11.设备适配 | Device Adaptation
12.扩展 | Extensions
13.滤镜效果 | Filter Effects
14.灵活的框布局 | Flexible Box Layout
15.字体 | Fonts
16.片段模块 | Fragmentation
17.全屏 API | Fullscreen API
18. 生成内容 | Generated Content
19.网格布局 | Grid Layout
20.图像值 | Image Values
21.初始线格局 | Inline Layout
22.列表和计数器 | Lists & Counters
23.逻辑属性 | Logical Properties
24.面具 | Masking
25.媒体查询 | Media Queries
26.杂项 | Miscellaneous
27.Miscellaneous Level 1
28.Miscellaneous Level 2
29.运动路径 | Motion Path
30. 多列布局 | Multi-column Layout
31.命名空间 | Namespaces
32.项目模型 | Object Model View
33.网页媒体 | Paged Media
34.定位布局 | Positioned Layout
35.伪元素 | Pseudo-
36.节奏大小 | Rhythmic Sizing
37. Ruby布局 | Ruby Layout
38.可缩放矢量图形 | Scalable Vector Graphics
39.滚动快照 | Scroll Snap
40.选择 | Selectors
41.形状 | Shapes
42.文本 | Text
43.文字装饰 | Text Decoration
44.变换 | Transforms
45.值和单位 | Values & Units
46.变量 | Variables
47.写入模型 | Writing Modes
48.CSS 教程
49.CSS 创建
50.CSS Id 和 Class选择器
51.CSS 简介
52.CSS 盒子模型
53.CSS Table(表格)
54.CSS 列表样式(ul)
55.CSS 链接(link)
56.CSS Fonts(字体)
57.CSS Text(文本)
58.CSS Backgrounds(背景)
59.CSS Display(显示) 与 Visibility(可见性)
60.CSS 尺寸 (Dimension)
61.CSS 分组和嵌套
62.CSS 轮廓(outline)属性
63.CSS Border(边框)
64.CSS 图像透明/不透明
65.CSS 导航栏
66.CSS 伪元素
67.CSS 伪类
68.CSS Float(浮动)
69.CSS Position(定位)
70.CSS 总结
71.CSS 属性选择器
72.CSS 媒体类型
73.CSS 图像拼合技术
74.CSS 实例
75.CSS 组合选择符
76.响应式 Web 设计 – 框架
77.响应式 Web 设计 – 视频(Video)
78.CSS 提示工具(Tooltip)
79.CSS 布局 Overflow
80.CSS 计数器
81.CSS 表单