불투명도 사용 불투명도 수준을 설정하려면 JavaScript의 속성을 사용하십시오. 다음 코드를 실행하여 JavaScript로 요소의 불투명도 수준을 설정할 수 있습니다 -
예시
<!DOCTYPE html> <html> <head> <style> #box { width: 450px; background-color: gray; } </style> </head> <body> <p>Click below to set Opacity.</p> <button type="button" onclick="display()">Set Opacity</button> <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> <script> function display() { document.getElementById("box").style.opacity = "0.5"; } </script> </body> </html>