CSS [attribute=value] 選擇器
- 上一页 [attribute]
- 下一页 [attribute~=value]
- 返回上一层 Manwal ng Selector ng CSS
定義和用法
CSS [attribute=value]
選擇器用於選擇具有指定屬性且屬性值完全匹配的元素。
實例
例子 1
選擇並設置所有 target="_blank" 的 <a> 元素的樣式。同時選擇並設置所有 lang="it" 的 <p> 元素的樣式:
a[target="_blank"] { background-color: yellow; } p[lang="it"] { background-color: salmon; }
例子 2
將 <input type="text"> 元素的寬度設置為 100px。然而,當它獲得焦點時,將其寬度設置為 250px:
input[type="text"] { width: 100px; } input[type="text"]:focus { width: 250px; }
CSS 語法
[attribute = value] { css declarations; }
技術細節
版本: | CSS2 |
---|
瀏覽器支持
表格中的數字表示完全支持該選擇器的首個瀏覽器版本。
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
4.0 | 7.0 | 2.0 | 3.1 | 9.6 |
- 上一页 [attribute]
- 下一页 [attribute~=value]
- 返回上一层 Manwal ng Selector ng CSS