如何使用 JavaScript 在單條宣告中設定所有的 outline 屬性?


要在一份宣告中設定所有 outline 屬性,請使用 outline 屬性。它設定以下屬性:outline-width、outline-style 和 outline-color。

範例

你可以嘗試執行以下程式碼來了解如何處理 outline 屬性 −

即時演示

<!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 瀏覽量

開啟您的 事業

透過完成該課程獲得認證

開始
廣告