当项目不使用JavaScript的所有可用空间时,如何在柔性容器内的项目之间设置对齐方式?
在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>