如何使用 JavaScript 偏移一個輪廓並在邊框邊緣之外對其進行繪製?


如要偏移輪廓,請使用 outlineOffset 屬性。它允許你在邊框邊緣之外繪製輪廓。

你可以嘗試執行以下程式碼,以使用 JavaScript 偏移輪廓並在邊框邊緣之外對其進行繪製。

示例

即時演示

<!DOCTYPE html>
<html>
   <head>
      <style>
         #box {
            width: 450px;
            background-color: orange;
            border: 3px solid red;
            margin-left: 20px;
         }
      </style>
   </head>
   <body>
      <p>Click below to add Outline Offset.</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 Offset</button>
      <br>
      <script>
         function display() {
            document.getElementById("box").style.outline = "thick solid";
            document.getElementById("box").style.outlineColor = "#5F5F5F";
            document.getElementById("box").style.outlineOffset = "7px";
         }
      </script>
   </body>
</html>

更新於:30-7-2019

170 次瀏覽

開啟你的事業

透過完成課程獲得認證

開始
廣告
© . All rights reserved.