search
HomeWeb Front-endCSS TutorialLet's talk about how to use CSS filters to achieve concave and smooth rounded corners.

How to use CSS to achieve concave and smooth rounded corners? The following article will show you how to skillfully use CSS filters to achieve concave and smooth rounded corners. I hope it will be helpful to you!

Let's talk about how to use CSS filters to achieve concave and smooth rounded corners.

One day, the group members raised a question in the group, how to use CSS to achieve the following layout:

Lets talk about how to use CSS filters to achieve concave and smooth rounded corners.

In the CSS world, if it is just the following effects, it is still very easy to achieve:

Lets talk about how to use CSS filters to achieve concave and smooth rounded corners.

Once the rounded corners or wave effects are involved, the difficulty will increase. a lot of.

It is actually quite troublesome to achieve this kind of continuous smooth curve. Of course, it is not completely impossible. This article will show you some possible ways to use CSS to achieve the above-mentioned concave and smooth rounded corners effect. [Recommended learning: css video tutorial]

Use the connection of circles to achieve

The first method is relatively stupid. We can use the connection of multiple circles to achieve this.

First, we will implement a rectangle with a rectangle dug out inside:

<div></div>

The core CSS code is as follows:

div {
    height: 200px;
    background: 
        linear-gradient(90deg, #9c27b0, #9c27b0 110px, transparent 110px, transparent 190px, #9c27b0 190px),
        linear-gradient(90deg, #9c27b0, #9c27b0);
    background-size: 100% 20px, 100% 100%;
    background-position: 0 0, 0 20px;
    background-repeat: no-repeat;
}

Get such a graphic (there are many ways to implement it, Here I am using gradients):

Lets talk about how to use CSS filters to achieve concave and smooth rounded corners.

Next, I use pseudo elements to superimpose three circles, which is probably like this:

Lets talk about how to use CSS filters to achieve concave and smooth rounded corners.

div {
    ...
    &::before {
        position: absolute;
        content: "";
        width: 40px;
        height: 40px;
        border-radius: 50%;
        background: #000;
        left: 90px;
        box-shadow: 40px 0 0 #000, 80px 0 0 #000;
    }
}

Slightly modify the colors of the three circles, and we can get the following effect:

Lets talk about how to use CSS filters to achieve concave and smooth rounded corners.

As you can see, this kind of effect through the three circles The effect achieved by superposition is not very good. It can only be said to be barely restored. If the background color is not a solid color, it will be confusing:

Lets talk about how to use CSS filters to achieve concave and smooth rounded corners.

You can click here for the complete code Here: CodePen Demo - Smooth concave rounded corners

https://codepen.io/Chokcoco/pen/oNGgyeK

Achieved through filter

The following is this article The key point is to introduce a way to use filters to achieve this effect.

You may be surprised when you hear about filters, huh? This effect seems to have nothing to do with filters, right?

The following is the moment to witness the miracle.

First of all, we only need to implement such a graphic:

<div class="g-container">
    <div class="g-content">
        <div class="g-filter"></div>
    </div>
</div>
.g-container {
    position: relative;
    width: 300px;
    height: 100px;
    
    .g-content {
        height: 100px;
        
        .g-filter {
            height: 100px;
            background: radial-gradient(circle at 50% -10px, transparent 0, transparent 39px, #000 40px, #000);
        }
    }
}

Get such a simple graphic:

Lets talk about how to use CSS filters to achieve concave and smooth rounded corners.

See this, definitely You may be wondering, why does this graphic need to be nested with 3 layers of divs? Wouldn't a div be enough?

is because we have to use the magical combination of filter: contrast() and filter: blur().

Let’s simply transform the above code and carefully observe the similarities and differences with the above CSS:

.g-container {
    position: relative;
    width: 300px;
    height: 100px;
    
    .g-content {
        height: 100px;
        filter: contrast(20);
        background-color: white;
        overflow: hidden;
        
        .g-filter {
            filter: blur(10px);
            height: 100px;
            background: radial-gradient(circle at 50% -10px, transparent 0, transparent 29px, #000 40px, #000);
        }
    }
}

We added filter: contrast(20 ) and background-color: white, added filter: blur(10px) to .g-filter. The magic happened, we got such an effect:

Lets talk about how to use CSS filters to achieve concave and smooth rounded corners. Use the contrast filter to remove the blurred edges of the Gaussian blur,

Turn the original right angle into a rounded corner

, Amazing. Get a more intuitive feeling through a Gif:

Lets talk about how to use CSS filters to achieve concave and smooth rounded corners.There are several details to note here:

  • .g-content

    This layer needs to set the background and overflow: hidden (you can try to remove it yourself to see the effect)

  • The outside The right angle has also become a rounded corner
  • Based on the second point above, the right angle on the outside has also become a rounded corner. If you want this rounded corner to be a right angle as well, there is
. g-container

At this layer, we can add a pseudo element to this layer to cover the four corners into right angles: <pre class='brush:php;toolbar:false;'>.g-container { &amp;::before { content: &quot;&quot;; position: absolute; top: 0; left: 0; bottom: 0; right: 0; z-index: 1; background: radial-gradient(circle at 50% -10px, transparent 0, transparent 60px, #000 60px, #000 0); } }</pre>We can get that only the middle part is a concave rounded corner , the remaining four corners are right angles:

Lets talk about how to use CSS filters to achieve concave and smooth rounded corners.

You can click here for the complete code: CodePen Demo - Smooth concave rounded corners By filter

https://codepen.io/Chokcoco/pen/JjroBPo

Of course, due to the blur filter applied to the above smooth concave rounded corners, it is not recommended to place DOM inside. It is best to treat it as For background use, internal content can be superimposed on top of it in other ways.

Regarding the magical fusion effect of filter: contrast() and filter: blur(), you can click on this article to learn more - you Unknown CSS filter skills and details

https://github.com/chokcoco/iCSS/issues/30

Finally

implementation of this article There are several other ways to create concave smooth rounded corners. The essence is similar to the first method in this article. They are all superimposed deception methods and will not be listed one by one. The core purpose of this article is to introduce the second filter method.

Okay, this article ends here, I hope this article will be helpful to you :)

(Learning video sharing: web front-end)

The above is the detailed content of Let's talk about how to use CSS filters to achieve concave and smooth rounded corners.. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:掘金社区. If there is any infringement, please contact admin@php.cn delete
What is CSS Grid?What is CSS Grid?Apr 30, 2025 pm 03:21 PM

CSS Grid is a powerful tool for creating complex, responsive web layouts. It simplifies design, improves accessibility, and offers more control than older methods.

What is CSS flexbox?What is CSS flexbox?Apr 30, 2025 pm 03:20 PM

Article discusses CSS Flexbox, a layout method for efficient alignment and distribution of space in responsive designs. It explains Flexbox usage, compares it with CSS Grid, and details browser support.

How can we make our website responsive using CSS?How can we make our website responsive using CSS?Apr 30, 2025 pm 03:19 PM

The article discusses techniques for creating responsive websites using CSS, including viewport meta tags, flexible grids, fluid media, media queries, and relative units. It also covers using CSS Grid and Flexbox together and recommends CSS framework

What does the CSS box-sizing property do?What does the CSS box-sizing property do?Apr 30, 2025 pm 03:18 PM

The article discusses the CSS box-sizing property, which controls how element dimensions are calculated. It explains values like content-box, border-box, and padding-box, and their impact on layout design and form alignment.

How can we animate using CSS?How can we animate using CSS?Apr 30, 2025 pm 03:17 PM

Article discusses creating animations using CSS, key properties, and combining with JavaScript. Main issue is browser compatibility.

Can we add 3D transformations to our project using CSS?Can we add 3D transformations to our project using CSS?Apr 30, 2025 pm 03:16 PM

Article discusses using CSS for 3D transformations, key properties, browser compatibility, and performance considerations for web projects.(Character count: 159)

How can we add gradients in CSS?How can we add gradients in CSS?Apr 30, 2025 pm 03:15 PM

The article discusses using CSS gradients (linear, radial, repeating) to enhance website visuals, adding depth, focus, and modern aesthetics.

What are pseudo-elements in CSS?What are pseudo-elements in CSS?Apr 30, 2025 pm 03:14 PM

Article discusses pseudo-elements in CSS, their use in enhancing HTML styling, and differences from pseudo-classes. Provides practical examples.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Atom editor mac version download

Atom editor mac version download

The most popular open source editor