Pure CSS star shape [duplicate]

爱⌒轻易说出口 提交于 2019-11-29 09:12:30
misterManSam

Let's break it into pieces:

The yellow borders are actually set as transparent in the final product so they don't show. They are yellow here to show how the borders look.

As commented above, this answer shows the idea behind the basic triangle shape.

The div by itself:

<div id="star-five"></div>

Combining the :before pseudo element is the same as this:

<div id="star-five">
    <div id="before"></div>
</div>

Finally, combining the :after pseudo element is the same as this:

<div id="star-five">
    <div id="before"></div>

    <div id="after"></div>
</div>

Now you overlap each element precisely using position: absolute; and rotate with transform as needed to get the final product:

Let's visualise it!

You can draw a triangle using large borders, which is what is happening there. Then they're just rotating and positioning the triangles in a star pattern.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!