CSS :focus 偽類
- 上一頁 :first-of-type
- 下一頁 :focus-visible
- 返回上一層 CSS 偽類參考手冊
定義和用法
CSS :focus
偽類用于選擇并設置獲得焦點的元素的樣式。
實例
例子 1
選擇并設置輸入字段獲得焦點時的樣式:
input:focus { background-color: yellow; }
例子 2
當輸入字段獲得焦點時,更改背景顏色和寬度:
input:focus { background-color: yellow; width: 250px; }
CSS 語法
:focus { css declarations; }
技術細節
版本: | CSS2 |
---|
瀏覽器支持
表格中的數字指定了完全支持該偽類的首個瀏覽器版本。
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
4.0 | 8.0 | 2.0 | 3.1 | 9.6 |
相關頁面
教程:CSS 偽類
- 上一頁 :first-of-type
- 下一頁 :focus-visible
- 返回上一層 CSS 偽類參考手冊