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


要設定輪廓屬性,請使用 outline 屬性。它允許你設定輪廓的顏色、樣式和偏移。

示例

你可以嘗試執行以下程式碼,在 JavaScript 的一個宣告中設定所有輪廓屬性 −

即時演示

<!DOCTYPE html>
<html>
   <head>
      <style>
         #box {
            width: 450px;
            background-color: orange;
            border: 3px solid red;
         }
      </style>
   </head>
   <body>
      <p>Click below to add Outline.</p>
      <div id="box">
         <p>This is a div. This is a div. This is a div. This is a div. This is a div.</p>
         <p>This is a div. This is a div. This is a div. This is a div. This is a div.</p>
         <p>This is a div. This is a div. This is a div. This is a div. This is a div.</p>
      </div>
      <br>
      <button type="button" onclick="display()">Set Outline</button>
      <br>
      <script>
         function display() {
            document.getElementById("box").style.outline = "thick solid #5F5F5F";
         }
      </script>
   </body>
</html>

更新於: 23-Jun-2020

111 次瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.