Home > Web Front-end > CSS Tutorial > How Can I Simulate an Inset Border-Radius Using CSS3 Gradients?

How Can I Simulate an Inset Border-Radius Using CSS3 Gradients?

Linda Hamilton
Release: 2024-12-05 03:16:11
Original
517 people have browsed it

How Can I Simulate an Inset Border-Radius Using CSS3 Gradients?

Simulating Inset Border-Radius with CSS3 Gradients

Achieving an inset border-radius effect purely with CSS3 poses a challenge. However, using CSS3 gradients, you can simulate the desired effect.

Lea Verou's Gradient Solution

Lea Verou devised an innovative solution that utilizes four transparent radial gradients positioned at opposite corners of the element.

div.round {
    background:
        -moz-radial-gradient(0 100%, circle, rgba(204,0,0,0) 14px, #c00 15px),
        -moz-radial-gradient(100% 100%, circle, rgba(204,0,0,0) 14px, #c00 15px),
        -moz-radial-gradient(100% 0, circle, rgba(204,0,0,0) 14px, #c00 15px),
        -moz-radial-gradient(0 0, circle, rgba(204,0,0,0) 14px, #c00 15px);
    background:
            -o-radial-gradient(0 100%, circle, rgba(204,0,0,0) 14px, #c00 15px),
            -o-radial-gradient(100% 100%, circle, rgba(204,0,0,0) 14px, #c00 15px),
            -o-radial-gradient(100% 0, circle, rgba(204,0,0,0) 14px, #c00 15px),
            -o-radial-gradient(0 0, circle, rgba(204,0,0,0) 14px, #c00 15px);
    background:
            -webkit-radial-gradient(0 100%, circle, rgba(204,0,0,0) 14px, #c00 15px),
            -webkit-radial-gradient(100% 100%, circle, rgba(204,0,0,0) 14px, #c00 15px),
            -webkit-radial-gradient(100% 0, circle, rgba(204,0,0,0) 14px, #c00 15px),
            -webkit-radial-gradient(0 0, circle, rgba(204,0,0,0) 14px, #c00 15px);
    background-position: bottom left, bottom right, top right, top left;
        -moz-background-size: 50% 50%;
        -webkit-background-size: 50% 50%;
    background-size: 50% 50%;
    background-repeat: no-repeat;
}
Copy after login

These gradients create a set of transparent curves that resemble an inset border radius. You can adjust the colors and radii to create different styles.

Browser Support and Fallback

This technique depends on support for RGBA and gradients, which are not supported in older browsers, particularly Internet Explorer. Therefore, it's crucial to use this solution as a progressive enhancement or provide an image-based fallback for legacy browsers.

The above is the detailed content of How Can I Simulate an Inset Border-Radius Using CSS3 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