CSS로 전체 화면 비디오 배경을 만들려면 코드는 다음과 같습니다 -
예시
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1" /> <style> * { box-sizing: border-box; } body { margin: 0; font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; font-size: 17px; } .backgroundVideo { position: fixed; right: 0; bottom: 0; min-width: 100%; min-height: 100%; } .content { position: fixed; bottom: 0; background: rgba(0, 0, 0, 0.5); color: #f1f1f1; width: 100%; padding: 20px; } .playPauseBtn { width: 200px; font-size: 18px; padding: 10px; border: none; background: rgb(72, 22, 167); color: #fff; cursor: pointer; opacity: 0.8; } .playPauseBtn:hover { opacity: 1; } </style> </head> <body> <video autoplay muted loop class="backgroundVideo"> <source src="https://cdn.videvo.net/videvo_files/video/free/2019- 05/small_watermarked/190416_10_Drone1_04_preview.webm" type="video/mp4"/> </video> <div class="content"> <h1>Heading</h1> <h2>Some Sample text</h2> <button class="playPauseBtn">Pause</button> </div> <script> document .querySelector(".playPauseBtn") .addEventListener("click", toggleVideo); var video = document.querySelector(".backgroundVideo"); var btn = document.querySelector(".playPauseBtn"); function toggleVideo() { if (video.paused) { video.play(); btn.innerHTML = "Pause"; } else { video.pause(); btn.innerHTML = "Play"; } } </script> </body> </html>
출력
위의 코드는 다음 출력을 생성합니다 -