CSS3:border-radius隱藏的威力

來源:互聯網
上載者:User

標籤:blog   http   io   ar   color   os   使用   sp   on   

這篇文章將簡述使用CSS3的border-radius來畫圓、半圓和四分之一圓,並如何利用它們。

如何使用border-radius屬性

下面是border-radius屬性最基本的使用方法。

1234567
.round {border-radius: 5px; /* 所有角都使用半徑為5px的圓角,此屬性為CSS3標準屬性 */-moz-border-radius: 5px; /* Mozilla瀏覽器的私人屬性 */-webkit-border-radius: 5px; /* Webkit瀏覽器的私人屬性 */border-radius: 5px 4px 3px 2px; /* 四個半徑值分別是左上方、右上方、右下角和左下角 */}

關於在IE裡怎麼實現圓角,可以看《Excellent Article Which Included Ways to Achieve Rounded Corners in IE》這篇文章。

 

1.用border-radius畫圓實心圓

,是用border-radius屬性畫出來的一個完美的實心圓。畫實心圓的方法是高度和寬度相等,並且把border的寬度設為高度和寬度的一半。代碼如下。

123456
#circle {width: 200px;height: 200px;background-color: #a72525;-webkit-border-radius: 100px;}
空心圓

通過border-radius屬性畫空心圓和畫實心圓的方法差不多,只是border的寬度只能小於高度和寬度的一半。代碼如下。

1234567
#circle {width: 200px;height: 200px;background-color: #efefef; /* Can be set to transparent */      border: 3px #a72525 solid;-webkit-border-radius: 100px;}
虛線圓

1234567
#circle {width: 200px;height: 200px;background-color: #efefef; /* Can be set to transparent */      border: 3px #a72525 dashed;-webkit-border-radius: 100px 100px 100px 100px;}
2.半圓和四分之一圓半圓

以本例來講,半圓的畫法是把寬度設為高度的一半,並且也只設定左上方和左下角的半徑。代碼如下。

123456
#quartercircle {width: 200px;height: 200px;background-color: #a72525;-webkit-border-radius: 200px 0 0 0;}
四分之一圓

四分之一圓的實現方法是把高度和寬度設定為相等,只設定一個圓角,其半徑等於高度或寬度。本例代碼如下。

123456
#quartercircle {width: 200px;height: 200px;background-color: #a72525;-webkit-border-radius: 200px 0 0 0;}
更多玩法

看了這麼多執行個體後,你完全可以自己創造更多玩法,如:

虛線的半圓和四分之一圓。

配合position屬性做一個月亮。

配合position、RGBa和z-index這些屬性做一個本文開頭的色彩維恩圖。

原文:The hidden power of border-radius

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.