HTML DOM 样式 alignContent 属性
htmlweb developmentfront end technology更新于 2024/5/26 16:12:17
alignContent 属性用于对齐弹性框或网格中的项目。当项目未使用所有可用空间时,该属性用于沿垂直轴对齐项目。
语法
以下是语法 −
设置 alignContent 属性 −
object.style.alignContent = "stretch|center|flex-start|flex-end|space-between|space-around|initial|inherit"
值
以下是值 −
| 值 | 描述 |
|---|---|
| Stretch | 这是默认值,用于拉伸项目以适应容器。 |
| Center | 用于将项目定位在容器的中心。 |
| flex-start | 将项目定位在容器的开头。 |
| flex-end | 将项目定位在容器的末尾容器。 |
| space-between | 将项目放置在行与行之间留有空间的位置。 |
| space-around | 将项目放置在行前、行间和行后留有空间的位置。 |
| Initial | 将此属性设置为初始值。 |
| Inherit | 继承父级属性值。 |
示例
让我们看一下 alignContent 属性的示例 −
<!DOCTYPE html>
<html>
<head>
<style>
#container {
width: 180px;
height: 220px;
padding: 10px;
border: 1px solid #333;
display: flex;
flex-flow: row wrap;
align-content: space-around;
}
.ele {
width: 60px;
height: 60px;
background-color: skyblue;
}
.ele:nth-child(2n) {
background-color: orange;
}
</style>
<script>
function changeAlign(){
document.getElementById("container").style.alignContent="flex-start";
}
</script>
</head>
<body>
<div id="container">
<div class="ele"></div>
<div class="ele"></div>
<div class="ele"></div>
<div class="ele"></div>
<div class="ele"></div>
<div class="ele"></div>
</div>
<p>Change the align content property of the above div by clicking the belwo button</p>
<button onclick="changeAlign()">CHANGE</button>
</body>
</html>
输出
这将产生以下输出 −

点击"更改"按钮 −

相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

