"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to Create an Inverted Border-Radius Effect in CSS?

How to Create an Inverted Border-Radius Effect in CSS?

Published on 2024-12-22
Browse:604

How to Create an Inverted Border-Radius Effect in CSS?

Creating Inverted Border-Radius Effects

Question:

Can an inverted border-radius effect be achieved where the corners appear to curve inward?

Answer:

Native CSS's border-radius property does not permit negative values that would result in an inverted effect. However, here's an alternative approach using CSS:

Add four additional elements within the container, ensuring they extend slightly beyond its boundaries. These elements should match the background color of the page, creating an illusion of the page content underneath. Position these elements strategically around the corners and apply a border-radius to achieve the inverted effect.

Code Snippet:

#main {
    margin: 40px;
    height: 100px;
    background-color: #004C80;
    position: relative;
    overflow: hidden;
}

#main div {
    position: absolute;
    width: 20px;
    height: 20px;
    border-radius: 100%;
    background-color: #FFF;
}

.top { top: -10px; }
.bottom { bottom: -10px; }
.left { left: -10px; }
.right { right: -10px; }
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3