- Web Developer's Reference Guide
- Joshua Johanan Talha Khan Ricardo Zea
- 295字
- 2021-07-09 20:18:25
Border radius
With this property, we can not only make rounded corners but also circles, ellipses, and other interesting shapes.
I admit that the term "rounded corners" is far less obscure than "border radius".
border-radius
The border-radius
CSS property allows us to make rounded corners on almost any HTML element, and it looks like this:
border-radius: 20px;
Description
The border-radius
attribute is also the shorthand syntax for the border-top-left-radius
, border-top-right-radius
, border-bottom-right-radius
, and border-bottom-left-radius
properties.
Using either a circle or an ellipse, we can create rounded corners:
There are two values: a length value and a percentage value.
Length value
This is when we use one of the following units: px
, em
, in
, mm
, cm
, vw
, and so on.
Percentage value
This is when we use percentages such as 50%
, 85%
, and so on.
We can use, one, two, three, or four values in the same declaration. We can also use a slash symbol, "/
", to separate groups of values.
Tip
Sometimes, the background color or texture "bleeds" over the rounded corners in some browsers. Use background-clip
to fix this issue.
CSS:
/*Longhand*/ .element { border-top-left-radius: 20px; border-top-right-radius: 20px; border-bottom-right-radius: 20px; border-bottom-left-radius: 20px; } /*Shorthand*/ .element { border-radius: 20px; } /*Two values: top-left-and-bottom-right - top-right-and-bottom-left*/ .element-1 { border-radius: 70px 7px; } /*Three values: top-left - top-right-and-bottom-left - bottom-right*/ .element-2 { border-radius: 70px 7px 20px; } /*Four values: top-left - top-right - bottom-right - bottom-left*/ .element-3 { border-radius: 70px 7px 20px 150px; } /*Values pided with a slash "/" symbol */ .element-4 { border-radius: 70px 7px/20px 30px; } /*Circle*/ .element-5 { border-radius: 200px; } /*Ellipse*/ .element-6 { height: 100px; border-radius: 100%; } /*Pill*/ .element-7 { height: 100px; border-radius: 100px; } /*Half Pill: top-left - top-right - bottom-right - bottom-left*/ .element-8 { height: 100px; border-radius: 100px 0 0 100px; }
Here is a demo in CodePen: http://tiny.cc/css-border-radius
- Web應用系統開發實踐(C#)
- Learn Type:Driven Development
- Developing Middleware in Java EE 8
- 數據結構習題精解(C語言實現+微課視頻)
- The DevOps 2.4 Toolkit
- 自然語言處理Python進階
- Java高并發核心編程(卷1):NIO、Netty、Redis、ZooKeeper
- LabVIEW虛擬儀器入門與測控應用100例
- Essential C++(中文版)
- 小型編譯器設計實踐
- 時空數據建模及其應用
- Maker基地嘉年華:玩轉樂動魔盒學Scratch
- Training Systems Using Python Statistical Modeling
- BackTrack 5 Cookbook
- OpenCL異構并行計算:原理、機制與優化實踐