首页前端开发CSScss样式画图小汽车

css样式画图小汽车

时间2023-12-02 14:49:03发布访客分类CSS浏览386
导读:在网页中可以使用CSS样式来画图,接下来让我们一起来尝试画一辆小汽车。.car {width: 200px;height: 100px;background-color: #bfbfbf;position: relative;}.car:b...

在网页中可以使用CSS样式来画图,接下来让我们一起来尝试画一辆小汽车。

.car {
    width: 200px;
    height: 100px;
    background-color: #bfbfbf;
    position: relative;
}
.car:before {
    content: "";
    width: 60px;
    height: 60px;
    background-color: #4d4d4d;
    position: absolute;
    bottom: 0;
    left: 20px;
    border-radius: 10px;
}
.car:after {
    content: "";
    width: 60px;
    height: 60px;
    background-color: #4d4d4d;
    position: absolute;
    bottom: 0;
    right: 20px;
    border-radius: 10px;
}
.car .door {
    width: 30px;
    height: 60px;
    background-color: #4d4d4d;
    position: absolute;
    bottom: 0;
    left: 45px;
    border-radius: 10px;
}
.car .roof {
    width: 100px;
    height: 40px;
    background-color: #4d4d4d;
    position: absolute;
    top: 0;
    left: 50%;
    margin-left: -50px;
    border-radius: 10px;
}
.car .wheel {
    width: 50px;
    height: 50px;
    background-color: #333;
    position: absolute;
    bottom: 0;
    left: 0;
    border-radius: 50%;
    transform: translateX(20px);
}
.car .wheel:last-child {
    left: auto;
    right: 0;
    transform: translateX(-20px);
}
    

上述代码中,我们使用了:before和:after伪元素来分别画出了小汽车的左右两个车灯,使用.door选择器画出了车门,使用.roof选择器画出了车顶,使用.wheel选择器画出了车轮。

最后,我们可以在HTML中使用.car类来展示这辆小汽车:

div class="car">
    div class="door">
    /div>
    div class="roof">
    /div>
    div class="wheel">
    /div>
    div class="wheel">
    /div>
    /div>
    

通过以上的CSS样式和HTML结构,我们成功地画出了一辆小汽车,可以在网页上展示。

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!


若转载请注明出处: css样式画图小汽车
本文地址: https://pptw.com/jishu/564892.html
css样式用什么呈现 css样式格式命名。ab

游客 回复需填写必要信息