樣式在指定範圍內使用 CSS 設定值元素


要為值在指定範圍內的<input> 元素設定樣式,請使用 CSS :in-range 選擇器。您可以嘗試執行以下程式碼來實現 :in-range 選擇器

示例

即時演示

<!DOCTYPE html>
<html>
   <head>
      <style>
         input:in-range {
            border: 3px dashed orange;
            background: yellow;
         }
      </style>
   </head>
   <body>
      <input type = "number" min = "5" max = "10" value = "9">
      <p>The style only works for the value entered i.e. 9</p>
   </body>
</html>

更新於:2020 年 6 月 21 日

103 次瀏覽

開啟你的 職業生涯

完成課程獲得認證

開始
廣告
© . All rights reserved.