DIV CSS 佈局教程網

CSS border-left 左邊框語法、簡寫與實作
編輯:布局基本知識     

border-left 是 border 的細分屬性,只控制左側那一條邊。當設計只需要一條左側線條時,它比 border 更直接。

一、語法

border-left: border-width || border-style || border-color;

三個值分別是寬度、樣式、顏色,順序不拘。

div { border-left: 2px solid red; }

意思是:左邊框 2px 寬、實線、紅色。

二、簡寫前後對比

拆開寫:

border-left-width: 2px;
border-left-color: #00F;
border-left-style: dashed;

合併寫:

border-left: 2px dashed #00F;

程式碼量明顯下降,效果完全相同,也更有利於頁面載入。

三、實作範例

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>border-left 範例</title>
<style>
.exp { border-left: 3px solid #F00; }
</style>
</head>
<body>
<div class="exp">左邊框範例</div>
</body>
</html>

四、經典應用:引言區塊

左邊框最常見的用途就是做引用樣式:

blockquote {
border-left: 4px solid #E5E5E5;
padding: 8px 0 8px 16px;
margin: 16px 0;
color: #555;
}

一條左側色條加上內距,就能讓引言從內文中清楚獨立出來,且不干擾右側的閱讀節奏。

五、重點

border-left 的語法、結構、用法與 border 完全一致,唯一差別是作用範圍只有左邊。其他三邊對應 border-right、border-top、border-bottom,寫法可以互相類推。

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