一、实现效果及html代码
1、实现效果
2、html代码
<body>
<div class="container">
<div style="background-color: red">1</div>
<div style="background-color: blue">2</div>
<div style="background-color: green">3</div>
<div style="background-color: pink">4</div>
<div style="background-color: orange">5</div>
<div style="background-color: orchid">6</div>
<div style="background-color: burlywood">7</div>
<div style="background-color: royalblue">8</div>
<div style="background-color: coral">9</div>
</div>
</body>
二、flex布局实现
<style>
.container {
display: flex;
flex-wrap: wrap;
}
.container div {
width: 33%;
text-align: center;
height: 150px;
}
</style>
三、float布局实现
<style>
.container div {
float: left;
width: 33%;
height: 150px;
}
</style>
四、grid布局实现
<style>
.container {
display: grid;
grid-template-columns: auto auto auto;
}
.container div {
height: 150px;
text-align: center;
}
</style>
五、table布局实现
html结构
<body>
<div class="container">
<div class="item">
<div style="background-color: red">1</div>
<div style="background-color: blue">2</div>
<div style="background-color: green">3</div>
</div>
<div class="item">
<div style="background-color: pink">4</div>
<div style="background-color: orange">5</div>
<div style="background-color: orchid">6</div>
</div>
<div class="item">
<div style="background-color: burlywood">7</div>
<div style="background-color: royalblue">8</div>
<div style="background-color: coral">9</div>
</div>
</div>
</body>
<style>
.container {
display: table;
width: 100%;
height: 100%;
}
.item {
display: table-row;
}
.item div {
display: table-cell;
height: 150px;
}
</style>