What is the method for setting a video as the background of my div?

I've been trying to set a Youtube video as the background of my div. After researching online, I found that many people followed these steps:

Welcome

Easy to use.

So easy to use, even your dog could do it.

Elite Clientele

We have all the dogs, the greatest dogs.

Guaranteed to work.

Find the love of your dog's life or your money back.

Initially, the video was fullscreen. So I adjusted the header height to 70% and changed the overflow to hidden. However, because the header position is fixed, anything I add after the header shows up on top of the video. Removing position: fixed messes up the video. Any suggestions on how to achieve this without using a fixed header?

I included some old HTML to demonstrate how any div placed after the "header" ends up overlapping it.

EDIT: The website currently appears like this: this image illustrates a header div with a video background occupying 70% of the viewport height. Is there a way to replicate the same result without having a fixed header?

Answer №1

Simply incorporate a position element into your content. I've set it to absolute for use with your example, but you can also use relative if the parent is positioned in absolute. Then adjust the content placement to be 70% from the top.

If you want your header to overlay your content when scrolling, consider setting its z-index value to 100 (although 10 or even 1 could work as well).

.container-fluid{
  padding:0;
}

/* Styles for the header section */
.header{
  background: #000;
  position: fixed;
  z-index: 100; /* Ensures the header overlaps everything else */
  top: 0; right: 0; bottom: 0; left: 0;
  height: 70%;
  overflow: hidden;
}

.vid-container, .header iframe {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: -1;
}

.header-text{
  color:white;
  z-index:1;
}

.row {
    color: red; /* Debugging purposes */
}

/* Positioning the content absolutely and setting the top coordinate to match the header's height */

.row {
  position: absolute;
  top: 70%;
}

/**/

@media (min-aspect-ratio: 16/9) {
    .vid-container { height: 300%; top: -100%; }
}
@media (max-aspect-ratio: 16/9) {
    .vid-container { width: 300%; left: -100%; }
}
link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<body class = "container-fluid">
<div class="header">
  <div class="vid-container">
    <iframe width="560" height="315" 
    src="https://www.youtube.com/embed/DXA3JYdFKAE? controls=0&showInfo=0&rel=0&autoplay=1&loop=1&playlist=DXA3JYdFKAE&start=0" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
  </div>
  <div class="header-text">
    <h1>Welcome</h1>
  </div>
</div>
<div class="row">
  <div class="col-lg-4 feature">
    <i class="fas fa-check-circle orange-tick"></i>
    <h3>Easy to use.</h3>
    <p>So easy to use, even your dog could do it.</p>
  </div>
  <div class="col-lg-4 feature">
    <i class="fas fa-bullseye target"></i>
    <h3>Elite Clientele</h3>
    <p>We have all the dogs, the greatest dogs.</p>
  </div>
  <div class="col-lg-4 feature">
    <i class="fas fa-heart heart"></i>
    <h3>Guaranteed to work.</h3>
    <p>Find the love of your dog's life or your money back.</p>
  </div>
</div>

In any case, you might want to experiment with using position:absolute instead of fixed. Let me know if that achieves the desired effect.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I'm attempting to slightly adjust the alignment of the text to the center, but it keeps causing the text to shift

I am facing an issue where I want to slightly center text, but whenever I add just 1px of padding-left, it moves to a new line. In my layout, I have 2 columns each occupying 50% width of the screen. One column contains only a photo while the other has a ba ...

extracting the value of a chosen radio button in AngularJS using HTML

When attempting to retrieve the selected value from a radio button, I am encountering an issue where choosing "teacher" still shows as "student." Here is the HTML file: <!DOCTYPE html> <html ng-app="phase2"> ... (HTML code continues) Rige ...

How can you achieve a seamless or infinite scrolling effect on a webpage?

My idea is as follows: Imagine a long web page where, instead of the scrolling coming to an abrupt stop when the user reaches the end, I want the page to reload from the bottom and allow the scrolling to continue seamlessly. Specifics Picture this - as ...

What is the best way to use selenium to extract all p-tags and their corresponding h2-tags?

I am looking to retrieve the title and content from an article: <h2><span>Title1</span></h2> <p>text I want</p> <p>text I want</p> <h2><span>Title2</span></h2> <p>text I want< ...

Currently, I am expanding my knowledge of PHP and MySQL by working on a dynamic form that utilizes arrays. As I progress through the project,

One of my recent projects involved creating dynamic rows in a form using code. I managed to save the data in an array and display it using a foreach loop, but I'm facing challenges when trying to insert this data into a database. Here's a glimps ...

The functionality of the jQuery button subscription is completely ineffective

I am attempting to display search results on the same page, but I'm encountering an issue. Here is my code: <form id="myForm"> <input id="filter_id" type="text"/> <input type="submit" id="load_results" value="Search" /> < ...

Is the menu not appearing in the header section of the HTML/CSS?

Hey there, I'm a new student diving into the world of HTML/CSS. I've been working on creating a page layout, but for some reason my menu links are appearing under the header section instead of within it. I'm a bit confused and could really u ...

reaching an adjustable Vertical Dimension

I am currently working on the front-end development of a new project. I'm using a mix of custom CSS and Bootstrap to create a responsive user interface. The current layout adjusts nicely with the browser width, but now I need to make it responsive in ...

Looking to implement an underline effect using CSS for the active tab that mimics the hover effect already applied

How can I ensure that the underline on active tabs (Domov) matches the hover effect on other tabs? The border-bottom currently creates a border that is lower than the hover effect, resulting in inconsistent underlines as seen on this page - (try moving ...

Converting XML to HTML with the help of XSLT transformation customization

I need assistance in adjusting the XSLT 1.0 transform within the provided xsl file to create an HTML version of the table coded in the attached XML file. The generated HTML output file should display the table from the XML file with alternating row backgro ...

Is it possible to adjust the height of input fields in MUI Reactjs?

Having trouble adjusting the height of input textfields using in-line css. <FormControl sx={{ "& .MuiOutlinedInput-notchedOutline": { borderColor: "blue", }, "&.Mui-focused .MuiOutlinedInpu ...

Display or conceal a div element depending on the user's choice

I am looking to hide inactive divs, but whenever I reload the page, all tab contents merge into one. The screenshot below shows the issue I'm facing. Screenshot Below is the code snippet: $('.tab a').on('click', function ...

The newly added radio button does not function as a separate group as expected

I currently have a set of radio buttons: <input type="radio" class='form-control' name="progress_type[]" value="Journal Papers"><span class='radio-label'>Journal Paper</span> <input type="radio" class='form-co ...

Troubleshooting a problem with CSS animations disappearing

I've been experimenting with CSS animations and I've run into a bit of a snag. I'm looking to create a div that fades in with a delay - meaning it won't be visible until the animation starts. Here's what I have so far: http://jsfi ...

Updating the information displayed in one section by selecting a button on the Google Maps infowindow located in a separate section

My webpage is divided into multiple divisions. One division contains a map using the Google Maps API with markers. When I click on a marker, an info window opens up. Now, I am attempting to place a button inside that info window which, when clicked, will ...

How can you prevent the browser from prompting to save your email and password when filling out a sign-up form?

I'm currently developing a PHP sign up form, but whenever I click on the sign up button, the browser prompts me to save the email and password. Is there a way to prevent this from happening? ...

At what point will the browser display changes made to css using jQuery?

When I run my JavaScript code in Firebug, it looks like this: tr=$(this).parent('tr'); tr.find('.img-delete').css('display','block'); However, I am unable to see the change reflected on the browser. Is there a wa ...

A single column in Bootstrap displaying text vertically

Looking to rotate the "VERTICAL_TEXT" (third bootstrap column) by 90 degrees, I attempted the code below: <div class="row"> <div class="col-xs-2" style="background-color: yellow;"> <span>FOO1</span><br/> & ...

The Mat-Card inside the Mat-Table fails to expand to its full width when using overflow-x property

When I inserted a mat-card in a mat-table and set the width to 100%, I noticed that when scrolling with overflow-x from left to right, the whole wrapper was not completely filled with the mat-card. Can anyone suggest CSS optimizations for this issue? Here ...

Placement of "like" and "reblog" options within tumblr

Having issues with the button placement on my tumblr page. The Like button is in the correct position, but the Reblog button keeps appearing at the beginning of the post. On subsequent posts, it even extends outside the post block. Additionally, the text a ...