当项目未使用 JavaScript 的所有可用空间时,如何设置灵活容器内项目之间的对齐方式?
javascriptobject oriented programmingfront end technology更新于 2024/7/2 15:40:17
使用 JavaScript 中的 alignContent 属性设置灵活容器内项目之间的对齐方式。
示例
您可以尝试运行以下代码,在 JavaScript 中实现 alignContent 属性 −
<!DOCTYPE html>
<html>
<head>
<style>
#box {
border: 1px solid #000000;
width: 240px;
height: 150px;
flex-flow: row wrap;
align-content: space-around;
display: flex;
}
#box div {
height: 80px;
width: 80px;
}
</style>
</head>
<body>
<div id = "box">
<div style = "background-color:orange;" ID = "myID1">DIV1</div>
<div style = "background-color:blue;" id = "myID2">DIV2</div>
<div style = "background-color:yellow;" id = "myID3">DIV3</div>
</div>
<button onclick="display()"> Set </button>
<script>
function display() {
document.getElementById("box").style.alignContent = "space-between";
}
</script>
</body>
</html>
相关文章
有用资源
javascript 参考教程 - 该教程包含有关 javascript 的更多信息:https://www.cainiaomax.com/javascript/

