Home > Web Front-end > CSS Tutorial > How to Achieve Rounded Corners for Both the Inside and Outside of a Box with CSS?

How to Achieve Rounded Corners for Both the Inside and Outside of a Box with CSS?

DDD
Release: 2024-11-16 10:04:03
Original
1054 people have browsed it

How to Achieve Rounded Corners for Both the Inside and Outside of a Box with CSS?

Achieving Rounded Corners for Both the Inside of a Box and Its Border

Background

Creating rounded corners for both the inside and outside of a box can enhance the visual appeal of a design. However, it can be challenging to achieve this effect without affecting the borders of both elements. This guide explores how to achieve this desired effect using CSS.

Inner Border Calculations

To apply rounded corners to the inner box, you need to calculate the inner border radius. This is done by subtracting the border width from the outer border radius.

  • Inner Border Radius = Outer Border Radius - Border Width

In this case, with an outer border radius of 6px and a border width of 5px:

  • Inner Border Radius = 6px - 5px = 1px

Updated CSS:

.radius-all { border-radius: 6px; }
.template-bg { background: #FFF; }
.template-border { border: 5px solid rgba(255, 255, 255, 0.2); }
Copy after login

Applying General Borders

If you're using separate boxes for the border and inner content, apply the border-radius property and its vendor-specific versions to both boxes for consistent rounded corners.

Example (Separate Boxes):

<div>
Copy after login
Copy after login

Example (Single Box):

.rounded-borders {
    border-radius: 5px;
}
Copy after login
<div>
Copy after login
Copy after login

The above is the detailed content of How to Achieve Rounded Corners for Both the Inside and Outside of a Box with 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