如何使用JavaScript在一个声明中设置所有Outline属性?

若要设置轮廓属性,请使用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>