1 回答

TA貢獻1865條經(jīng)驗 獲得超7個贊
您可能需要考慮使用 CSS 網(wǎng)格來完成此任務(wù):
grid-template-columns: repeat(auto-fit, 100px); //100px being the width of your choosing
這是代碼:
超文本標記語言
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div class="container">
<div class="block">1</div>
<div class="block">2</div>
<div class="block">3</div>
<div class="block">4</div>
</div>
</body>
</html>
CSS
.block{
background-color: grey;
}
.container{
display: grid;
grid-gap: 5px;
grid-template-columns: repeat(auto-fit, 100px);
justify-content: space-around; //you can still use justify-content: space-around
}
小提琴:小提琴鏈接
- 1 回答
- 0 關(guān)注
- 157 瀏覽
添加回答
舉報