<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flexbox Layout</title>
<style>
.container {
display: flex;
flex-wrap: wrap;
justify-content: flex-start;
/* 从左到右排列 */
}
.item {
width: calc(33.33% - 20px);
/* 每行显示3个元素,考虑间距 */
margin: 10px;
/* 元素间隔 */
background-color: lightblue;
box-sizing: border-box;
/* 让元素的border和padding计入宽度 */
}
</style>
</head>
<body>
<div class="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
<div class="item">6</div>
<div class="item">7</div>
<div class="item">8</div>
<div class="item">9</div>
<div class="item">10</div>
<div class="item">11</div>
</div>
</body>
</html>
flex布局从左到右排列及换行保持间距的代码(模板)
最新推荐文章于 2024-08-18 10:54:05 发布