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

DDD
Release: 2024-10-31 11:09:29
Original
947 people have browsed it

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:

<code class="css">#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; }</code>
Copy after login
<code class="html"><div id="main">
    <div class="top left"></div>
    <div class="top right"></div>
    <div class="bottom left"></div>
    <div class="bottom right"></div>
</div></code>
Copy after login

The above is the detailed content of How to Create an Inverted Border-Radius Effect in CSS?. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!