如何使用 JavaScript 在單個宣告中設定所有輪廓屬性?


如需在一個宣告中設定所有輪廓屬性,請使用 outline 屬性。將設定以下屬性:outline-width、outline-style 和 outline-color。

示例

你可以嘗試執行以下程式碼以瞭解如何使用輪廓屬性 −

試用

<!DOCTYPE html>
<html>
   <head>
      <style>
         #box {
            border: 2px dashed blue;
         }
      </style>
   </head>
   <body>
      <div id="box">This is a div.</div>
      <br>
      <button type="button" onclick="display()">Click to set Outline</button>
      <script>
         function display() {
            document.getElementById("box").style.outline = "5px solid red";
         }
      </script>
   </body>
</html>

更新時間: 23-6 月 -2020

93 次觀看

開啟你的 事業

完成課程獲得認證

開始
廣告
© . All rights reserved.