示例一
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Grid布局</title>
</head>
<style>
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
background-color: #f6f6f6;
}
.headTitle {
text-align: center;
padding: 30px 0;
font-size: 26px;
color: #555;
}
.layout {
min-height: 500px;
background-color: #fff;
border-radius: 10px;
margin: 0 auto;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.05);
padding: 30px;
}
.flex .box {
width: 300px;
height: 200px;
background-color: #7c9fb0;
border-radius: 8px;
padding: 10px;
display: flex;
align-items: center;
justify-content: center;
color: #fff;
margin-bottom: 40px;
}
.flex {
width: 1400px;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.grid {
width: 80%;
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
grid-template-rows: 1fr 1fr;
gap:40px
;
}
.grid .box {
background-color: #7c9fb0;
border-radius: 8px;
padding: 10px;
display: flex;
align-items: center;
justify-content: center;
color: #fff;
}
.gridbilibli {
width: 1400px;
display: grid;
grid-template-columns: repeat(5,1fr);
gap: 40px;
}
.gridbilibli .box {
background-color: #7c9fb0;
border-radius: 8px;
padding: 10px;
display: flex;
align-items: center;
justify-content: center;
color: #fff;
}
.gridbilibli .box:nth-child(1) {
grid-column: span 2;
grid-row: span 2;
}
</style>
<body>
<div class="headTitle">flex布局(最后一行要么都居中要么都居左,不合适,除非数量固定)</div>
<div class="layout flex">
<div class="box">box方块</div>
<div class="box">box方块&