使用css画出一个五角星

使用 CSS 绘制一个五角星可以通过多种方式完成,其中一种是使用 ::before::after 伪元素以及 border 属性。以下是一个简单的示例:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>五角星 CSS</title>
    <style>
        .star {
            position: relative;
            width: 0;
            height: 0;
            border-right: 100px solid transparent;
            border-bottom: 70px solid red;
            border-left: 100px solid transparent;
            transform: rotate(35deg);
            margin: 50px;
        }

        .star::before {
            content: "";
            position: absolute;
            top: 3px;
            left: -60px;
            width: 0;
            height: 0;
            border-right: 60px solid transparent;
            border-bottom: 70px solid red;
            border-left: 60px solid transparent;
            transform: rotate(-35deg);
        }

        .star::after {
            content: "";
            position: absolute;
            top: -33px;
            left: -20px;
            width: 0;
            height: 0;
            border-right: 60px solid transparent;
            border-bottom: 70px solid red;
            border-left: 60px solid transparent;
            transform: rotate(-35deg);
        }
    </style>
</head>
<body>
    <div class="star"></div>
</body>
</html>

这段代码创建了一个红色的五角星。你可以根据需要调整颜色、大小和位置。这里的关键是使用 border 属性来形成星形的各个部分,并通过 transform: rotate(); 来调整它们的角度。

注意:这种方法可能不是创建五角星的最简洁或最语义化的方式,但它是一种相对简单且不需要 SVG 或其他复杂技术的方法。如果你需要更精细的控制或更复杂的形状,可能需要考虑使用 SVG 或其他图形库。

posted @   王铁柱6  阅读(33)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示