Web速查-索引

Alt text

定义

align-self 属性定义 flex 子项单独在侧轴(纵轴)方向上的对齐方式。

flex 属性是 flex-growflex-shrinkflex-basis 属性的简写属性。

语法

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

属性值

描述
auto 默认值。元素继承了它的父容器的 align-items 属性。如果没有父容器则为”stretch”。
stretch 元素被拉伸以适应容器。如果指定侧轴大小的属性值为’auto’,则其值会使项目的边距盒的尺寸尽可能接近所在行的尺寸,但同时会遵照’min/max-width/height’属性的限制。
center 元素位于容器的中心。弹性盒子元素在该行的侧轴(纵轴)上居中放置。(如果该行的尺寸小于弹性盒子元素的尺寸,则会向两个方向溢出相同的长度)。
flex-start 元素位于容器的开头。弹性盒子元素的侧轴(纵轴)起始位置的边界紧靠住该行的侧轴起始边界。
flex-end 元素位于容器的结尾。弹性盒子元素的侧轴(纵轴)起始位置的边界紧靠住该行的侧轴结束边界。
baseline 元素位于容器的基线上。如弹性盒子元素的行内轴与侧轴为同一条,则该值与’flex-start’等效。其它情况下,该值将参与基线对齐。
initial 设置该属性为它的默认值。
inherit 从父元素继承该属性。

实例

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>鱼C-零基础入门学习Web(Html5+Css3)</title>
<style>
#main {
width: 220px;
height: 180px;
border: 1px solid #3c3c3c;
display: flex;
align-items: flex-start;
}
#main div {
flex: 1;
}
#myBlueDiv {
align-self: center;
}
</style>
</head>
<body>
<div id="main">
<div style="background-color:coral;">A</div>
<div style="background-color:lightblue;" id="myBlueDiv">B</div>
<div style="background-color:lightgreen;">C ilovefishc.com 我爱鱼C</div>
</div>
</body>
</html>
A
B
C ilovefishc.com 我爱鱼C

浏览器支持

表格中的数字表示支持该属性的第一个浏览器版本号

Safari Chrome FireFox IE
3.1 4.0 3.0 8.0