- :first-line
- :first-letter
- :before
- :after
:first-line 為段落文字元素的首行樣式,也就是第一行的樣式, :first-letter 為段落文字元素的首字母樣式,也就是第一個字母的樣式,至於 :before 與 :after 分別為元素開頭與結束的樣式。
舉例如下
p:first-line {
letter-spacing: 3;
text-transform: uppercase;
}
p:first-letter {
font-size: 2em;
}
p:before, p:after {
font-size: 1.5em;
content: '@@';
}
/* 《程式語言教學誌》的範例程式
http://pydoing.blogspot.com/
檔名:demo42.css
功能:示範 CSS 2.1 樣式表的使用
作者:張凱慶
時間:西元 2011 年 7 月 */我們以下面的 HTML 文件載入
<html>
<head>
<title>網頁標題</title>
<link rel="stylesheet" type="text/css"
href="demo42.css">
</head>
<body>
<p>You ever have that feeling where you're not sure if
you're awake or still dreaming?</p>
<p>A prison for your mind.</p>
<p>Free your mind.</p>
<p>Believe the unbelievable.</p>
<p>There is no spoon.</p>
<p>I can only show you the door, you have to walk
through it.</p>
<p>Choice. The problem is choice.</p>
<p>Then tomorrow we may all be dead, but how would that
be different from any other day?</p>
<p>I have dreamed a dream, but now that dream has gone
from me.</p>
<p>Choice is an illusion, created between those with
power, and those without.</p>
<p>Because I choose to.</p>
<p>Everything that has a beginning has an end.</p>
</body>
</html>
<!-- 《程式語言教學誌》的範例程式
http://pydoing.blogspot.com/
檔名:demo42.html
功能:示範 CSS 2.1 樣式表的使用
作者:張凱慶
時間:西元 2011 年 7 月 -->瀏覽器 (broswer) 開啟如下

我們可以看到結果符合樣式設定,首先 :before 與 :after 設定成 1.5 被字型大小的 "@@"
p:before, p:after {
font-size: 1.5em;
content: '@@';
}
因此每個 <p> 元素的開頭與結束都是 1.5 倍字型大小的 @@ ,但是由於有設定 :first-letter
p:first-letter {
font-size: 2em;
}所以實際上開頭的 @@ 為 2em 。首行也符合樣式,都是間距為 3 的大寫字母
p:first-line {
letter-spacing: 3;
text-transform: uppercase;
}| 中英文術語對照 | |
|---|---|
| 擬元素選取器 | pseudo-element selector |
| 元素 | element |
| 樣式 | style |
| 瀏覽器 | broswer |
您可以繼續參考
基本概念
單位
選取器
@import 規則
階層
元素呈現方式 display
相關目錄
CSS 2.1 快速導覽
HTML, CSS 教材
首頁
參考資料
http://www.w3.org/TR/CSS21/selector.html
https://developer.mozilla.org/en/CSS/Getting_Started/Selectors
沒有留言:
張貼留言