Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> JavaScript

วิธีตั้งค่าสีของเส้น Outline รอบองค์ประกอบด้วย JavaScript

ใช้คุณสมบัติ outlineColor เพื่อกำหนดสีของเส้น outline สามารถใช้ชื่อสี, hex, rgb, hsl ได้

ตัวอย่าง

<!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 Color.</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 Color</button>
    <br>
    <script>
      function display() {
        document.getElementById("box").style.outline = "thick solid";
        document.getElementById("box").style.outlineColor = "#5F5F5F";
      }
    </script>
  </body>
</html>