為每一個已選中的元素新增 CSS 樣式


若要為每一個已選中的 <input> 元素新增樣式,請使用 CSS :checked 選擇器。你可以嘗試執行以下程式碼來實現 :checked 選擇器 -

示例

即時演示

<!DOCTYPE html>
<html>
   <head>
      <style>
         input:checked {
            height: 20px;
            width: 20px;
         }
      </style>
   </head>
   <body>
      <p>Fav sports:</p>
      <form action="">
         <input type = "checkbox" value = "Football">Football<br>
         <input type = "checkbox" value = "Cricket">Cricket<br>
         <input type = "checkbox" checked = "checked" value = "Tennis"> Tennis<br>
         <input type = "checkbox" value = "Badminton">Tennis
      </form>
   </body>
</html>

輸出

更新於:2020 年 6 月 22 日

140 次瀏覽

啟動你的 職業

透過完成課程來獲取證書

開始
廣告