Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> JavaScript

Cách gán đổ bóng (box-shadow) cho hộp với JavaScript?

Sử dụng thuộc tính boxShadow để thêm đổ bóng cho phần tử. Cú pháp: offsetX offsetY blurRadius color.

Ví dụ

<!DOCTYPE html>
<html>
  <head>
    <style>
      #box { border: thick solid green; width: 300px; height: 200px; }
    </style>
  </head>
  <body>
    <div id="box">Demo Text</div>
    <br><br>
    <button type="button" onclick="display()">Thêm đổ bóng</button>
    <script>
      function display() {
        document.getElementById("box").style.boxShadow = "20px 15px 25px orange";
      }
    </script>
  </body>
</html>