<html>
<head>
<meta charset="utf-8">
<title>TEST</title>
<style>
.grid {
display: table
transform:rotate(-45deg)
margin: 0 auto
}
.grid > .grid-tr {
display: table-row
}
.grid > .grid-tr > .grid-td {
display: table-cell
width: 120px
height: 120px
border: 2px solid rgba(255,255,255,1)
background-color: aqua
}
</style>
</head>
<body>
<div class="grid">
<div class="grid-tr">
<div class="grid-td"></div>
</div>
<div class="grid-tr">
<div class="grid-td"></div>
<div class="grid-td"></div>
</div>
<div class="grid-tr">
<div class="grid-td"></div>
<div class="grid-td"></div>
<div class="grid-td"></div>
</div>
<div class="grid-tr">
<div class="grid-td"></div>
<div class="grid-td"></div>
<div class="grid-td"></div>
<div class="grid-td"></div>
</div>
</div>
</body>
</html>
想放图片的话直接将 img标签放到 grid-td的div里面去。
思路很简单,看似不规则的排列实际是规则的,与其一个一个将div旋转,不如放入一个容器里面排列好,然后旋转了-45° 。
<!DOCTYPE html><html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
html, body{margin: 0 padding: 0}
.box{margin: 0 auto width: 400px transform: rotate(-45deg)}
span{display: inline-block width: 50px height: 50px margin: 0 1px 2px 0 background-color: lightblue transition: 1s}
span:hover{transform: scale(3) background-color: red}
</style>
</head>
<body>
<div class="box">
<div>
<span></span>
</div>
<div>
<span></span>
<span></span>
</div>
<div>
<span></span>
<span></span>
<span></span>
</div>
<div>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
<div>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
</div>
</body>
</html>
代码实现的是不规则排列和鼠标滑过放大,至于点击出现左右箭头切换就要用到JS了