
再把小黄人平分给每一个小盒子
/* 要满足boxes且满足big的情况 */
.boxes.big {
width: 600px;
height: 600px;
}
.boxes.big .box {
transform: rotateZ(360deg);
}
一个特定的元素同时标记为重要 ( important ) 和警告 ( warning )
"important warning">
.important {font-weight:bold;}
.warning {font-style:italic;}
.important.warning {background:silver;}
https://www.w3school.com.cn/css/css_selector_class.asp
* {
box-sizing: border-box;
}
body {
background-color: rgb(220, 250, 241);
font-family: 'Courier New', Courier, monospace;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
overflow: hidden;
}
.magic {
background-color: rgb(104, 72, 184);
color: aliceblue;
font-family: 'Courier New', Courier, monospace;
border: 0;
border-radius: 3px;
font-size: 26px;
padding: 12px 20px;
/* 设置为手指鼠标模式 */
cursor: pointer;
/* 设置固定定位 */
position: fixed;
top: 200px;
letter-spacing: 1px;
box-shadow: 0 3px rgba(82, 73, 189, 0.5);
/* 最高层,防止点击不出来 */
z-index: 100;
}
.magic:focus {
outline: none;
}
.magic:active {
box-shadow: none;
transform: translateY(2px);
}
.boxes {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
width: 500px;
height: 500px;
/* position: relative; */
transition: .4s ease;
}
/* 要满足boxes且满足big的情况 */
.boxes.big {
width: 600px;
height: 600px;
}
.boxes.big .box {
transform: rotateZ(360deg);
}
.box {
background-image: url('https://media.giphy.com/media/EZqwsBSPlvSda/giphy.gif');
background-repeat: no-repeat;
background-size: 500px 500px;
width: 125px;
height: 125px;
transition: .4s ease;
position: relative;
}
.box::after {
content: '';
background-color: rgb(134, 125, 218);
position: absolute;
top: 8px;
right: -15px;
height: 100%;
width: 15px;
transform: skewY(45deg);
}
.box::before {
content: '';
background-color: rgb(134, 125, 218);
position: absolute;
bottom: -15px;
left: 8px;
height: 15px;
width: 100%;
transform: skewX(45deg);
}
<button id="btn" class="magic">magicbutton>
<div id="boxes" class="boxes big">div>
<script>
const boxesContainer = document.getElementById('boxes')
const btn = document.getElementById('btn')
//点击切换:big是否可见
btn.addEventListener('click', () => boxesContainer.classList.toggle('big'))
// 创建小盒子
function createBoxes () {
for (let i = 0; i < 4; i++) {
for (let j = 0; j < 4; j++) {
const box = document.createElement('div')
box.classList.add('box')
box.style.backgroundPosition = `${-j * 125}px ${-i * 125}px`
boxesContainer.appendChild(box)
}
}
}
createBoxes()
script>
点击magic后