search
HomeWeb Front-endCSS TutorialCSS3 border-radius border rounded corners

1.1 Rounded corner attributes

CSS3 provides 5 types of rounded corner attributes:

border-radius: Set the rounded corner styles of 4 borders at the same time.

border-top-left-radius: Set the rounded corner style of the upper left corner border.

border-top-right-radius: Set the rounded corner style of the upper right corner border.

border-bottom-left-radius: Set the rounded corner style of the lower left corner border.

border-bottom-right-radius: Set the rounded corner style of the lower right corner border.

Example:

CSS3 border-radius border rounded corners

1.2 Browser support

Minimum version support: IE 9, Chrome 4

1.3 Reference information

Specification: https://www.w3.org/TR/css3- background/#the-border-radius

Documentation: https://developer.mozilla.org/zh-CN/docs/Web/CSS/border-radius

2. The format and type of value

border The value of the -*-radius attribute can set the horizontal radius and vertical radius respectively; if the vertical radius is omitted, the vertical radius defaults to the value of the horizontal radius.

For each value, the supported units are fixed length and percentage. If you set the percentage format, the percentage of the horizontal radius refers to the width of the border, and the percentage of the vertical radius refers to the height of the border.

The combination is as follows (taking border-radius as an example):

1) border-radius:20px; // Indicates that the horizontal radius and vertical radius of the fillet are both 20px in length.

2) border-radius:20px/40px; // Indicates that the length of the horizontal radius of the fillet is 20px and the length of the vertical radius is 20px.

3) border-radius:20%; // Indicates that the horizontal radius and vertical radius of the fillet are both 20% of the respective border lengths.

4) border-radius:20%/30%; // Indicates that the horizontal radius of the fillet is 20% of the border width, and the vertical radius is 20% of the border height.

5) border-radius:20px/30%; // Indicates that the horizontal radius length of the fillet is 20px, and the vertical radius is 20% of the border height.

Example:

CSS3 border-radius border rounded corners

3. Border-radius 1~4 parameter description

border-radius can set the same value for the four corners at once, or you can set the rounded corner style for the four corners separately.

The secret lies in setting the number of border-radius parameters.

First, let’s take a look at the parameter description of border-radius in the CSS specification: [ | ]{1,4} [ / [ | ]{1,4} ] ?

It can be known that the number of parameters of border-radius ranges from 1 to 4. Here we should pay attention to the use of point horizontal radius and vertical radius respectively: first set the horizontal radius of the four corners in border-radius and then set Vertical radius of 4 corners.

The following explains the meanings of parameters 1~4 respectively:

3.1 Number of parameters: 1

Explanation: The rounded corner styles of the 4 borders all use this setting.

Example: border-radius: 20px; //The 4 border rounded corner styles are all 20px

CSS3 border-radius border rounded corners

3.2 Number of parameters: 2

Description:

 parameter ①: the circles of the upper left corner and lower right corner border Angular style.

 The second parameter: the rounded corner style of the upper right corner and lower left corner borders.

Example: border-radius: 20px 40px; // Upper left corner and lower right corner: 20px; Upper right corner and lower left corner: 40px

CSS3 border-radius border rounded corners

3.3 Number of parameters: 3

Description:

 The ① parameter: the rounded corner style of the upper left corner border.

 The second parameter: the rounded corner style of the upper right corner and lower left corner borders.

 The ③ parameter: the rounded corner style of the lower right corner border.

Example: border-radius:20px 40px 60px; // Upper left corner: 20px; Upper right corner and lower left corner: 40px; Lower right corner: 60px Parameters: The rounded corner style of the upper left corner border.

 The second parameter: the rounded corner style of the upper right corner border. CSS3 border-radius border rounded corners

 The ③ parameter: the rounded corner style of the lower right corner border.

 The ④ parameter: the rounded corner style of the lower left corner border.

Example: border-radius:20px 40px 60px 80px; // Upper left corner: 20px; Upper right corner: 40px; Lower right corner: 60px; Lower left corner: 80px

3.4 Number of parameters: 4

Description:

 The first parameter: the rounded corner style of the upper left corner border.

 The second parameter: the rounded corner style of the upper right corner border. CSS3 border-radius border rounded corners

 The ③ parameter: the rounded corner style of the lower right corner border.

 The ④ parameter: the rounded corner style of the lower left corner border.

Example: border-radius:20px 40px 60px 80px; // Upper left corner: 20px; Upper right corner: 40px; Lower right corner: 60px; Lower left corner: 80px

4. Example

1. border-radius: 20px; // 同时设置4个边框圆角样式:水平半径和垂直半径都为20px
<br/>
<div class="div border-radius-1"></div><br/>
2.border-radius:20px 40px; // 左上角和右下角:20px;右上角和左下角:40px
<br/>
<div class="div border-radius-2"></div><br/>
3.border-radius:20px 40px 60px; // 左上角:20px;右上角和左下角:40px;右下角:60px
<br/>
<div class="div border-radius-3"></div><br/>
4.border-radius:20px 40px 60px 80px; // 左上角:20px;右上角:40px;右下角:60px;左下角:80px
<br/>
<div class="div border-radius-4"></div>
.border-radius-1{
  border-radius:20px;
}
.border-radius-2{
  border-radius:20px 40px
}
.border-radius-3{
  border-radius:20px 40px 60px;
}
.border-radius-4{
  border-radius:20px 40px 60px 80px;
}
.div{
  height:150px;
  width:160px;
  margin-left:20px;
  margin-top:10px;
  background-color: #82AF6F;
}

Statement
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
Iterating a React Design with Styled ComponentsIterating a React Design with Styled ComponentsApr 21, 2025 am 11:29 AM

In a perfect world, our projects would have unlimited resources and time. Our teams would begin coding with well thought out and highly refined UX designs.

Oh, the Many Ways to Make Triangular Breadcrumb Ribbons!Oh, the Many Ways to Make Triangular Breadcrumb Ribbons!Apr 21, 2025 am 11:26 AM

Oh, the Many Ways to Make Triangular Breadcrumb Ribbons

SVG Properties in CSS GuideSVG Properties in CSS GuideApr 21, 2025 am 11:21 AM

SVG has its own set of elements, attributes and properties to the extent that inline SVG code can get long and complex. By leveraging CSS and some of the forthcoming features of the SVG 2 specification, we can reduce that code for cleaner markup.

A Few Functional Uses for Intersection Observer to Know When an Element is in ViewA Few Functional Uses for Intersection Observer to Know When an Element is in ViewApr 21, 2025 am 11:19 AM

You might not know this, but JavaScript has stealthily accumulated quite a number of observers in recent times, and Intersection Observer is a part of that

Revisting prefers-reduced-motionRevisting prefers-reduced-motionApr 21, 2025 am 11:18 AM

We may not need to throw out all CSS animations. Remember, it’s prefers-reduced-motion, not prefers-no-motion.

How to Get a Progressive Web App into the Google Play StoreHow to Get a Progressive Web App into the Google Play StoreApr 21, 2025 am 11:10 AM

PWA (Progressive Web Apps) have been with us for some time now. Yet, each time I try explaining it to clients, the same question pops up: "Will my users be

The Simplest Ways to Handle HTML IncludesThe Simplest Ways to Handle HTML IncludesApr 21, 2025 am 11:09 AM

It's extremely surprising to me that HTML has never had any way to include other HTML files within it. Nor does there seem to be anything on the horizon that

Change Color of SVG on HoverChange Color of SVG on HoverApr 21, 2025 am 11:04 AM

There are a lot of different ways to use SVG. Depending on which way, the tactic for recoloring that SVG in different states or conditions — :hover,

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

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools