Home > Web Front-end > CSS Tutorial > How Can I Create CSS Circle Sectors Using Multiple Background Gradients?

How Can I Create CSS Circle Sectors Using Multiple Background Gradients?

Patricia Arquette
Release: 2024-11-27 09:04:09
Original
663 people have browsed it

How Can I Create CSS Circle Sectors Using Multiple Background Gradients?

Multiple Background Gradients for CSS Circle Sector Drawing

Drawing a circle with pure CSS is simple, but how do we create a sector of that circle?

Rather than trying to draw the colored portion, it's more efficient to draw the transparent portions in white.

pie {
    border-radius: 50%;
    background-color: green;
}

.ten {
    background-image:
        /* 10% = 126deg = 90 + ( 360 * .1 ) */
        linear-gradient(126deg, transparent 50%, white 50%),
        linear-gradient(90deg, white 50%, transparent 50%);
}
Copy after login

For greater than 50%, the first gradient needs to blend from transparent to the green color:

.seventyfive {
  background-image: linear-gradient(180deg, transparent 50%, green 50%), linear-gradient(90deg, white 50%, transparent 50%);
}
Copy after login

The above is the detailed content of How Can I Create CSS Circle Sectors Using Multiple Background Gradients?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template