DIV CSS 佈局教程網

您现在的位置: DIV+CSS佈局教程網 >> 網頁腳本 >  >> CSS入門知識 >> DIV十CSS布局 >> 布局實例
CSS 虛線邊框怎麼寫:六種常見變化一次看
編輯:布局實例     

虛線靠的是邊框屬性中的 dashed 樣式。為了方便觀察,以下範例的寬度都設為 350px、高度 50px。

一、四邊都是虛線

.hackhome { border: 1px dashed #000; height: 50px; width: 350px; }

HTML:<div class="hackhome">我的四邊為黑色虛線邊框</div>

這裡用的是邊框的縮寫形式,一次設定四邊為 1px 黑色虛線。

二、只有左邊是虛線

.hackhome-1 { border-left: 1px dashed #000; height: 50px; width: 350px; }

三、只有右邊是虛線

.hackhome-2 { border-right: 1px dashed #000; height: 50px; width: 350px; }

四、只有上邊是虛線

.hackhome-3 { border-top: 1px dashed #000; height: 50px; width: 350px; }

五、只有下邊是虛線

.hackhome-4 { border-bottom: 1px dashed #000; height: 50px; width: 350px; }

六、三邊虛線,一邊不要線

例如右邊完全不要邊框,其餘三邊保留黑色虛線:

.hackhome-5 {
  border: 1px dashed #000;
  border-right: 0;
  height: 50px;
  width: 350px;
}

寫法的關鍵在順序:先一口氣把四邊都設成 1px 虛線,再用 border-right:0 把其中一邊清掉。由於 CSS 後來者優先,最後就等於只設定了三邊。反過來寫(先設右邊為 0,再寫 border 縮寫)就會被整個覆蓋掉,這點要特別小心。

如果還想讓虛線更「虛」,可以試試 dotted,它呈現的是圓點而非短橫線,在分隔線或佔位區的場合很常用。

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