HTML DOM 样式 alignItems 属性
htmlweb developmentfront end technology更新于 2024/5/26 15:40:17
HTML DOM 样式 alignItems 属性用于指定灵活容器内项目的默认对齐方式。
语法
以下是语法 −
设置 alignItems 属性 −
object.style.alignContent = " stretch|center|flex-start|flex-end|baseline|initial|inherit"
值
以下可以是值 −
| 值 | 描述 |
|---|---|
| Stretch | 这是默认值,用于拉伸项目以适应容器。 |
| Center | 用于将项目定位在容器的中心。 |
| flex-start | 将项目定位在容器的开头。 |
| flex-end | 将项目定位在容器的末尾容器。 |
| baseline | 将项目定位到容器基线。 |
| initial | 将此属性设置为初始值。 |
| Inherit | 继承父级属性值。 |
示例
让我们看一下 Style alignItems 属性的示例 −
<!DOCTYPE html>
<html>
<head>
<style>
#container {
width: 180px;
height: 220px;
padding: 10px;
border: 1px solid #333;
display: flex;
align-items:flex-end;
flex-flow: row wrap;
}
.ele {
width: 60px;
height: 60px;
background-color: skyblue;
}
.ele:nth-child(2n) {
background-color: orange;
}
</style>
<script>
function changeAlign(){
document.getElementById("container").style.alignItems="baseline";
}
</script>
</head>
<body>
<h2>Demo Heading</h2>
<div id="container">
<div class="ele"></div>
<div class="ele"></div>
<div class="ele"></div>
</div>
<p>Change the align items property of the above div by clicking the button</p>
<button onclick="changeAlign()">CHANGE</button>
</body>
</html>
输出
这将产生以下输出 −

点击"更改"按钮 −

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

