CSS
 Computer >> コンピューター >  >> プログラミング >> CSS

CSSでフルスクリーンのビデオ背景を作成するにはどうすればよいですか?


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>

出力

上記のコードは次の出力を生成します-

CSSでフルスクリーンのビデオ背景を作成するにはどうすればよいですか?


  1. CSSで矢印を作成するにはどうすればよいですか?

    CSSで矢印を作成するためのコードは次のとおりです- 例 <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1" /> <style>    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;

  2. CSSで分割画面(50/50)を作成するにはどうすればよいですか?

    CSSで分割画面を作成するには、コードは次のとおりです- 例 <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <style>    body {       font-family: Arial;       color: white;    } &