在CSS中,有許多有趣的效果可以被實現(xiàn),比如CSS圓柱效果圖。下面是一個漂亮的實例:
.cylinder {
position: relative;
width: 300px;
height: 200px;
margin: 0 auto;
perspective: 600px;
}
.cylinder .sides {
position: absolute;
top: 0;
left: 50%;
transform: translateX(-50%);
width: 100%;
height: 100%;
background: #7ddbd1;
border-radius: 50% / 30%;
box-shadow: inset 0 0 20px rgba(0,0,0,0.8);
}
.cylinder .side {
position: absolute;
width: 100%;
height: 100%;
background: url(https://www.example.com/images/texture.jpg);
border-radius: inherit;
box-shadow: inset 0 0 20px rgba(0,0,0,0.8);
}
.cylinder .side:nth-child(1) {
transform: rotateY(0deg) translateZ(150px);
}
.cylinder .side:nth-child(2) {
transform: rotateY(60deg) translateZ(150px);
}
.cylinder .side:nth-child(3) {
transform: rotateY(120deg) translateZ(150px);
}
.cylinder .side:nth-child(4) {
transform: rotateY(180deg) translateZ(150px);
}
.cylinder .side:nth-child(5) {
transform: rotateY(240deg) translateZ(150px);
}
.cylinder .side:nth-child(6) {
transform: rotateY(300deg) translateZ(150px);
}
當(dāng)我們在HTML中添加以下代碼時:
<div class="cylinder">
<div class="sides"></div>
<div class="side"></div>
<div class="side"></div>
<div class="side"></div>
<div class="side"></div>
<div class="side"></div>
<div class="side"></div>
</div>
我們就可以得到一個漂亮的CSS圓柱效果圖了!