web前端——HTML+CSS实现九宫格文章来源:https://www.toymoban.com/news/detail-744161.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
body {
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background: rgb(224, 212, 203);
}
.container {
width: 300px;
height: 300px;
display: flex;
flex-wrap: wrap;
}
.container .item {
position: relative;
box-sizing: border-box;
width: 100px;
height: 100px;
border: 2px solid white;
background-image: url(A.jpg);
background-size: 300px 300px;
}
.container .item:nth-child(3n+1) {
left: -10px;
}
.container .item:nth-child(3n+2) {
left: 0px;
background-position-x: -100px;
}
.container .item:nth-child(3n+3) {
left: 10px;
background-position-x: -200px;
}
.container .item {
top: 10px;
background-position-y: -200px;
}
.container .item:nth-child(-n+6) {
top: 0px;
background-position-y: -100px;
}
.container .item:nth-child(-n+3) {
top: -10px;
background-position-y: 0px;
}
</style>
</head>
<body>
<div class="container">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
</body>
</html>
文章来源地址https://www.toymoban.com/news/detail-744161.html
到了这里,关于web前端——HTML+CSS实现九宫格的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!