CSS3 [attribute^=value] 選擇器

2018-11-05 14:19 更新

CSS3 [attribute^=value] 選擇器

實(shí)例

設(shè)置 class 屬性值以 "test" 開頭的所有 div 元素的背景色:

<!DOCTYPE html>
<html>
<head>
<style> 
div[class^="test"]
{
background:#ffff00;
}
</style>
</head>
<body>

<div class="first_test">The first div element.</div>
<div class="second">The second div element.</div>
<div class="test">The third div element.</div>
<p class="test">This is some text in a paragraph.</p>

</body>
</html>

瀏覽器支持

IE Firefox Chrome Safari Opera

所有主流瀏覽器都支持 [attribute^=value] 選擇器。

注釋:對于 IE8 及更早版本中的 [attribute^=value],必須聲明 <!DOCTYPE>

定義和用法

[attribute^=value] 選擇器匹配屬性值以指定值開頭的每個(gè)元素。

親自試一試 - 實(shí)例

設(shè)置 class 屬性值以 "test" 開頭的所有元素的背景色:

<html><!DOCTYPE html>
<html>
<head>
<style> 
[class^="test"]
{
background:#ffff00;
}
</style>
</head>
<body>

<div class="first_test">The first div element.</div>
<div class="second">The second div element.</div>
<div class="test">The third div element.</div>
<p class="test">This is some text in a paragraph.</p>

</body>
</html>

相關(guān)頁面

CSS 教程:CSS 屬性選擇器

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號