DIV CSS 佈局教程網

您现在的位置: DIV+CSS佈局教程網 >> 網頁腳本 >  >> CSS入門知識 >> CSS特效代碼
用 CSS3 border-radius 畫出一顆正圓
編輯:CSS特效代碼     

程式碼

<style type="text/css">
.circleHovertree {
  width: 30px;
  height: 30px;
  border: solid red 1px;
  display: inline-block;
  margin-left: 5px;
  border-radius: 60px;
  padding: 30px 30px;
}
</style>
<div class="circleHovertree"></div>
<span class="circleHovertree"></span>

border-radius 是簡寫屬性

它一次設定四個 border-*-radius。例如:

border-radius: 2em;

等價於:

border-top-left-radius: 2em;
border-top-right-radius: 2em;
border-bottom-right-radius: 2em;
border-bottom-left-radius: 2em;

這個屬性讓你能替元素加上圓角邊框,是告別「九宮格圓角圖」的關鍵。

  • 預設值:0
  • 繼承:否
  • 版本:CSS3
  • JavaScript:object.style.borderRadius = "5px"

語法與省略規則

border-radius: 1-4 length|% / 1-4 length|%;

依序設定每個角的水平與垂直圓角值。斜線左邊是水平半徑,右邊是垂直半徑,兩者不同時就能畫出橢圓角。省略規則如下:省略左下則等同右上;省略右下則等同左上;省略右上則等同左上。

至於「畫圓」本身,只要讓 border-radius 大於等於寬高的一半(例如寬 60px 就給 60px 以上,或直接寫 50%),四個角就會接合成正圓。上面範例給了 60px,因此即使加上 padding 後尺寸變大,仍然維持完整的圓形輪廓。

線上測試:https://hovertree.com/texiao/css/4b.htm

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved