Search code examples
htmlcsssvgcss-shapes

4 points rounded star shape


Star with four points

I am trying to get this star as pixel perfect as possible in CSS, here's what I tried so far, but it's a 5 angled star, and I want to have it only 4 points also how can I make the corners more rounded?

#star-five {
   margin: 50px 0;
   position: relative;
   display: block;
   color: red;
   width: 0px;
   height: 0px;
   border-right:  100px solid transparent;
   border-bottom: 70px  solid red;
   border-left:   100px solid transparent;
   -moz-transform:    rotate(35deg);
   -webkit-transform: rotate(35deg);
   -ms-transform:     rotate(35deg);
   -o-transform:      rotate(35deg);
}
#star-five:before {
   border-bottom: 80px solid red;
   border-left: 30px solid transparent;
   border-right: 30px solid transparent;
   position: absolute;
   height: 0;
   width: 0;
   top: -45px;
   left: -65px;
   display: block;
   content: '';
   -webkit-transform: rotate(-35deg);
   -moz-transform:    rotate(-35deg);
   -ms-transform:     rotate(-35deg);
   -o-transform:      rotate(-35deg);

}
#star-five:after {
   position: absolute;
   display: block;
   color: red;
   top: 3px;
   left: -105px;
   width: 0px;
   height: 0px;
   border-right: 100px solid transparent;
   border-bottom: 70px solid red;
   border-left: 100px solid transparent;
   -webkit-transform: rotate(-70deg);
   -moz-transform:    rotate(-70deg);
   -ms-transform:     rotate(-70deg);
   -o-transform:      rotate(-70deg);
   content: '';
}
<div id="star-five"></div>


Solution

  • Maybe you could use a gradient on the Black Four Pointed Star Unicode char:

    It has some compatibility issues (mostly caused by text-fill-color) but depending on your requirements it could get the job done.

    .four-point-star::after,
    .four-point-star::before {
        position: absolute;
        top: 0;
        left: 0;
        content: "\2726";
        font-size: 12rem;
    }
    
    .four-point-star::after { /* The foreground star */
        background: linear-gradient(135deg, rgba(255,191,183,1) 20%, rgba(243,44,117,1) 70%);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
    }
    
    .four-point-star::before { /* The star shadow */
        color: transparent;
        text-shadow: 2px 3px 10px rgba(242, 96, 85, 1);
    }
    
    /* Demo styling */
    body {
        background: #fbd629;
        padding: 0 2rem;
    }
    
    .four-point-star {
        position: relative;
    }
    <span class="four-point-star"></span>