CSS :before 選擇器
實例
每個 <p>元素之前插入內容:
p:before
{
content:"Read this: ";
}
{
content:"Read this: ";
}
定義和說明
:before 選擇器向選定的元素前插入內容。
使用content 屬性來指定要插入的內容。
流覽器支持
表格中的數字表示支持該屬性的第一個流覽器版本號。
選擇器 | |||||
---|---|---|---|---|---|
::before | 4.0 | 9.0 部分從8.0 |
3.5 | 3.1 | 7.0 部分從 4.0 |
注意: before在IE8中運行,必須聲明 <!DOCTYPE> 。
相關文章
CSS 教學: CSS Pseudo-elements
CSS 選擇器參考手冊: CSS :after 選擇器

更多實例
實例
在每個<p>之前插入的內容和樣式:
p:before
{
content:"Read this -";
background-color:yellow;
color:red;
font-weight:bold;
}
{
content:"Read this -";
background-color:yellow;
color:red;
font-weight:bold;
}
