css3中的border-radius

來源:互聯網
上載者:User

標籤:

重識css3中的border-radius

  大家可能都知道css3中的border-radius是用來定義圓角的,以前使用border-radius時,我都只是使用了border-radius帶一個參數的用法,但最近發現原來border-radius還可以根據所帶參數不同可以實現不同規則圓角的效果,下面就來講講border-radius所帶的幾種參數的含義吧。

一、border-radius帶一個參數

  border-radius帶1個參數時,比較容易理解,即這個參數適用於四個角。(這個還是很容易理解的,在這裡我就不囉嗦啦)

二、border-radius帶兩個參數

  帶兩個參數時,第一個參數表示表示上左和下右、第二個參數表示上右和下左。(嘿嘿,我是這樣記的——交叉相同)你可以試試下面的代碼來驗證呦。

  

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Document</title>    <style>        div{            width:200px;            height:200px;            border-radius: 50px 100px;            background:#FB9E84;        }    </style></head><body>    <div></div></body></html>
View Code三、border-radius帶三個參數時

  帶三個參數時,三個參數分別表示上左、上右和下左、下右。例子如下:

  

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Document</title>    <style>        div{            width:200px;            height:200px;            border-radius: 50px 20px 100px;            background:#FB9E84;        }    </style></head><body>    <div></div></body></html>
View Code

四、border-radius帶四個參數時

  帶四個參數時,也較容易理解,四個參數分別表示上左、上右、下右、下左——即按順時針方向來解析。例如:

  

border-radius: 20px 30px 50px 100px;

  得到的結果是這樣的:

  

五、border-radius還可以單獨設定各個圓角

  border-radius單獨設定圓角時,方法如下:

  上左:border-top-left-radius

  上右:border-top-right-radius

  下右:border-bottom-right-radius

  下左:border-bottom-left-radius

六、定製特殊的形狀——以斜杠“/”分開的參數

  當參數以斜杠來分開時,第一個參數表示圓角的水平半徑,第二個參數為圓角的垂直半徑,不太理解的可以看看下面的例子

  

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Document</title>    <style>        div{            width:200px;            height:200px;            border-radius: 200px/100px;            background:#FB9E84;        }    </style></head><body>    <div></div></body></html>
View Code

運行這個例子可以看到

  

七、4個圓角分別定製特殊的形狀

  我們知道可以使用斜杠來定製特殊的圓角,但在為4個圓角分別定製不同的特殊形狀時要注意使用的形式是border-radius:20px 30px 40px 50px/50px 40px 30px 20px;這種形式,而不是border-radius:20px/50px 30px/40px 40px/30px 50px/20px;(這種形式是不正確的),使用時一定要注意!

最後,使用斜杠定製特殊圓角的解析順序跟上面講的解析順序相同,大家按照上面的推算就可以了。

(PS: IE9+、Firefox 4+、Chrome、Safari 5+ 以及 Opera 支援 border-radius 屬性,IE8及更低版本不支援喲!)

 

css3中的border-radius

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.