CSS做海盗船要用CSS实现一艘海盗船,需要掌握一些基础知识和技巧。首先,我们可以利用CSS实现一个方形的船体,代码如下:.boat { width: 200px; height: 100px; ba...
CSS做海盗船
要用CSS实现一艘海盗船,需要掌握一些基础知识和技巧。
首先,我们可以利用CSS实现一个方形的船体,代码如下:
.boat {
width: 200px;
height: 100px;
background-color: #645A4F;
} 接着,加上三角形的帆,代码如下:
.boat::before {
content: "";
width: 0;
height: 0;
border-bottom: 100px solid #645A4F;
border-right: 100px solid transparent;
position: absolute;
top: -50px;
left: -100px;
}
.boat::after {
content: "";
width: 0;
height: 0;
border-top: 50px solid transparent;
border-right: 100px solid #645A4F;
position: absolute;
top: 50px;
left: -100px;
} 这样,我们就有了一艘具有形体的海盗船。
可以继续添加舵和桨,代码如下:
.boat .rudder {
width: 50px;
height: 50px;
background-color: #645A4F;
position: absolute;
top: 45px;
right: -50px;
transform: rotate(45deg);
}
.boat .oar {
width: 10px;
height: 80px;
background-color: #645A4F;
position: absolute;
bottom: -40px;
left: 50px;
transform: rotate(135deg);
}
.boat .oar::before {
content: "";
width: 10px;
height: 10px;
background-color: #645A4F;
position: absolute;
bottom: -10px;
left: 0;
border-radius: 50%;
} 这样,一艘基本的海盗船就完成了,通过改变颜色和细节的渐进变化,可以让其具有更丰富的表现和内涵。