Ashh
Ashh

Reputation: 7

How to set up website background as a video with blur?

I've been reading other Stack Overflow threads about this topic, but I can't seem to make it work.

I'm trying to figure out how to set up blurred video on loop as a background. Saw what I want to do on this Squarespace website: https://geoxor.me/

Haven't looked for any code for blur effect yet, as I'm still in the process of trying to make the video part work.

The code I'm using:

html

<video id="videoBackground" autoplay muted loop>
  <source src="https://player.vimeo.com/video/144855113">
</video>

css

#videoBackground {
  position: fixed;
  right: 0;
  bottom: 0;
  min-width:  100%;
  min-height: 100%;
}

I'd appreciate any advice, thanks for your time!

Upvotes: 0

Views: 2061

Answers (2)

Xenvi
Xenvi

Reputation: 887

You can wrap the video element in a container to center the video and set the width and height to fill screen. Then for the video, add filter: blur() to blur the background. Keep in mind this makes the edges blur white so you have to scale it bigger with transform: scale to hide the edge.

#videoBackground {
    width: inherit;
    height: inherit;
    -webkit-filter: blur(15px);
    -o-filter: blur(5px);
    filter: blur(5px);
    object-fit: cover;
    transform: scale(1.06); /* Hide edge blur */
}
#container {
    width: 100vw;
    height: 100vh;
    text-align: center;
    overflow: hidden;
}
<div id="container">
  <video id="videoBackground" autoplay muted loop>
    <source src="https://vod-progressive.akamaized.net/exp=1591758868~acl=%2A%2F1646772055.mp4%2A~hmac=ca002f29c4796df2b022404219ed50625d2baf4043cb622ce78dcb05f8c9edbb/vimeo-prod-skyfire-std-us/01/2944/15/389724705/1646772055.mp4">
  </video>
</div>

Upvotes: 1

SoliMoli
SoliMoli

Reputation: 786

video {
  object-fit: cover;
  width: 100vw;
  height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
    filter: blur(5px);
}

html, body {
  height: 100%;
}
html {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  font-size: 150%;
  line-height: 1.4;
}
body {
  margin: 0;
}

.viewport-header {
  position: relative;
  height: 50vh;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
}

h1 {
  font-family: 'Syncopate', sans-serif;
  color: #4a3a27;
  text-transform: uppercase;
  letter-spacing: 3vw;
  line-height: 1.2;
  font-size: 3vw;
  text-align: center;
  span {
    display: block;
    font-size: 10vw;
    letter-spacing: -1.3vw;
  }
}

main {
  width: 80vw;
  left: 10%;
  overflow: auto;
  background: rgba(black, 0.66);
  color: white;
  position: relative;
  padding: 1rem;
padding: 20px;
border: 1px solid #000;
text-align:center;
color: #4a3a27;
font-weight: bold;
}
<video src="https://css-tricks-post-videos.s3.us-east-1.amazonaws.com/blurry-trees.mov" autoplay loop playsinline muted></video>

<header class="viewport-header">
  <h1>
    Explore
    <span>Montana</span>
  </h1>
</header>

<main>
  I love Coding
</main>

Upvotes: 0

Related Questions