Search code examples
cssgeometrysegment

Divide a circle into 24 segments using css


I have created a circle using css. Now I want to divide it into 24 segments. How can I perform this using css. Help me. Here's my code for how I created circle:

<div class="circle"></div>
.circle{

            width: 50px;
            height: 50px;
            border-radius: 50%;
            background-color: blue
            }

Final Result looks like this:


Solution

  • You can perform it more easily by using Scalable Vector Graphics.

    code to draw circle:

    <svg xmlns="http://www.w3.org/2000/svg" version="1.1">
       <circle cx="150" cy="100" r="50" stroke="blue" stroke-width="2" fill="white"/>
    </svg>
    

    You may draw different lines, so that you can divide the circle into segments.

    Code for line:

    <svg xmlns="http://www.w3.org/2000/svg" version="1.1">
       <line x1="0" y1="0" x2="200" y2="200" style="stroke:rgb(255,0,0);stroke-width:2"/>
    </svg>