Web速查-索引

Alt text

定义

align-self指定了网格元素的垂直呈现方式。

语法

align-self: auto|stretch|normal|start|end|center

属性值

描述
auto 默认值,使用其父级元素盒子的 justify-items 属性的值,除非它没有父级元素, 或者是绝对定位的,这些情况下,auto 代表了 normal。
normal 这个关键字会导致类似于 stretch 的行为,除了具有高宽比或固有大小的盒子,它的行为类似于 start 。
stretch 拉伸。表现为垂直填充。
start 表现为网格垂直尺寸收缩为内容大小,同时沿着上网格线对齐显示。
end 表现为网格垂直尺寸收缩为内容大小,同时沿着下网格线对齐显示。
center 表现为网格垂直尺寸收缩为内容大小,同时在当前网格区域内部垂直居中对齐显示。

实例

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>鱼C-零基础入门学习Web(Html5+Css3)</title>
<style>
.grid-container {
display: grid;
grid-template-columns: repeat(8, 1fr);
grid-auto-rows: 100px;
grid-template-areas:
"a a a a b b b b"
"a a a a b b b b"
"c c c c d d d d"
"c c c c d d d d";
grid-gap: 10px;
background-color: lightblue;
padding: 10px;
}
.grid-container>div {
background-color: lightpink;
}
.item1 {
grid-area: a;
}
.item2 {
grid-area: b;
align-self: start;
}
.item3 {
grid-area: c;
align-self: end;
}
.item4 {
grid-area: d;
align-self: center;
}
</style>
</head>
<body>
<div class="grid-container">
<div class="item1">1</div>
<div class="item2">2</div>
<div class="item3">3</div>
<div class="item4">4</div>
</div>
</body>
</html>
1
2
3
4

浏览器支持

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

Safari Chrome FireFox IE
3.1 4.0 3.0 8.0