What is the best way to insert additional HTML elements beneath a video background that extends into the navigation bar?

*{
      padding: 0;
      margin: 0;
      text-decoration: none;
      list-style: none;
      box-sizing: border-box;
    }
    body{
      font-family: montserrat;
    }
    nav{
      height: 85px;
      width: 100%;
      z-index:1001;
    }

    label.logo{
      color: rgb(255, 255, 255);
      font-size: 35px;
      line-height: 80px;
      padding: 0 100px;
      font-weight: bold;
    }
    nav ul{
      float: right;
      margin-right: 20px;
    }
    nav ul li{
      display: inline-block;
      line-height: 80px;
      margin: 0 5px;
    }
    nav ul li a{
      color: white;
      font-size: 17px;
      padding: 7px 13px;
      border-radius: 3px;
      text-transform: uppercase;
    }
    a.active,a:hover{
      background: #1b9bff;
      transition: .5s;
    }
    .checkbtn{
      font-size: 30px;
      color: white;
      float: right;
      line-height: 80px;
      margin-right: 40px;
      cursor: pointer;
      display: none;
    }
    #check{
      display: none;
    }
    @media (max-width: 952px){
      label.logo{
        font-size: 30px;
        padding-left: 50px;
        position: fixed;
      }
      nav ul li a{
        font-size: 16px;
      }
    }

    @media (max-width: 858px){
      .checkbtn{
        display: block;
      }

      label.logo{
        color: white;
        font-size: 35px;
        line-height: 80px;
        padding: 0 0px;
        font-weight: bold;
      }

      nav {
        z-index: 1001;
      }

      ul{
        position: fixed;
        width: 100%;
        height: 100vh;
        background: #2c3e50;
        top: 80px;
        left: -100%;
        text-align: center;
        transition: all .5s;
      }
      nav ul li{
        display: block;
        margin: 50px 0;
        line-height: 30px;
      }
      nav ul li a{
        font-size: 20px;
      }
      a:hover,a.active{
        background: none;
        color: #0082e6;
      }
      #check:checked ~ ul{
        left: 0;
      }
    }


    .vid-background {
      z-index: -100;
      width:100%;
      height:80vh;
      overflow:hidden;
      position:fixed;
      top:0;
      left:0;
    }

    .reg-element {
      width:100%;
      height:80vh;
    }
<!DOCTYPE html>
    <html lang="en">
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" type="text/css" href="styles.css"/>
        <title>SnowWarrior Landing Page</title>
    </head>
    <body>
        <nav>
          <input type="checkbox" id="check">
          <label for="check" class="checkbtn">
            <img src="https://img.icons8.com/ios-glyphs/30/000000/menu--v1.png" alt="menu"/>
          </label>
          <label class="logo">SnowWarrior</label>
          <ul>
            <li><a href="#">Home</a></li>
            <li> <a href="#">Shop</a></li>
            <li> <a href="#">Contact</a></li>
          </ul>
        </nav>

        <div class="vid-background">
          <video autoplay loop muted>
            <source src="./assets/winter1.mp4">
          </video>
        </div>

        <section></section>

        <div class="reg-element">
          <span>Just saying</span>
        </div>
        
      </body>
    </html>

https://i.sstatic.net/GmlW3.png

The desired effect of the video overflowing into the navbar has been achieved intentionally. However, when attempting to add more div elements with text, they end up displaying behind the video rather than below it. As a beginner in HTML and CSS who just started two days ago, I might be missing something crucial. I would appreciate any guidance on correcting this issue.

Edit: Is there a way to embed a video in an HTML format that will display correctly on StackOverflow?

Answer №1

My Preferred Approach:

I advocate for the utilization of modern layout techniques like flexbox and grid instead of getting stuck in absolute positioning chaos. In my strategy, I structure the header with both the navigation and video as its sub-elements. The header is designed as a grid where the navigation occupies the top section explicitly, and the video spans the entire grid.

For smaller elements, I implement flexbox to flex along a single axis. When there is limited space, these components wrap onto a new line effortlessly, making the website responsive on narrower screens without the necessity for media queries.

If any part of this explanation seems unclear, feel free to drop a comment requesting further clarification.

* {
  padding: 0;
  margin: 0;
  text-decoration: none;
  list-style: none;
  box-sizing: border-box;
}

body {
  font-family: montserrat;
}

header {
  display: grid;
  grid-template: min-content 9fr / 1fr;
  width: 100%;
  min-height: 80vh;
  color: white;
}

nav {
  grid-area: 1 / 1 / 2 / 2;
  height: min-content;
  z-index: 10;
  display: flex;
  flex-flow: row wrap;
  justify-content: space-around;
  align-items: center;
  padding: 1rem;
  background-color: #0004;
  background-blend-mode: darken;
}

.vid-background {
  grid-area: 1 / 1 / 2 / 3;
}

.vid-background>* {
  width: 100%;
}

h1 {
  font-size: 2rem;
}

nav ul {
  flex-basis: max-content;
  display: flex;
  flex-flow: row wrap;
  justify-content: center;
}

nav ul li a {
  padding: .5rem 1rem;
  border-radius: 3px;
  color: inherit;
  text-transform: uppercase;
  transition: .5s;
}

a:active,
a:hover {
  background: #1b9bff;
}
<header>
  <nav>
    <h1>SnowWarrior</h1>
    <ul>
      <li><a href="#">Home</a></li>
      <li><a href="#">Shop</a></li>
      <li><a href="#">Contact</a></li>
    </ul>
  </nav>

  <div class="vid-background">
    <img src="https://source.unsplash.com/random/800x400">
  </div>
</header>
Just saying

Answer №2

The reason for this issue is due to the usage of position:fixed on all elements at the top, causing the subsequent element to disregard its presence.

To simplify, when using position:fixed and then introducing a div without a specified position, they will not interact with each other. Without knowledge of your intended outcome, I am unable to correct the code for you. Instead, I can inform you of this behavior in hopes that it guides you in the right direction - consider exploring the concept of positioning in CSS through tutorials.

Consider starting with Display:flex as a possible solution.

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

The carousel top position in Bootstrap 4 is not functioning properly

I am struggling to get the teal rectangle to move to the top of the carousel. I have set my carousel to have a position relative and my teal rectangle to have a position absolute with top="0", but it doesn't seem to be working properly. Instead of mov ...

Choosing the type attribute of an input tag by using a javascript variable as a condition: What's the best approach?

I am currently utilizing an input tag on the client side to receive text input. <input type="text" class="form-control" placeholder="Enter Message" id="messageText" autofocus/> My goal now is to dynamically set the type attribute based on a Javasc ...

A complete guide on utilizing *ngFor in Angular to display data rows

I am facing an issue with using *ngFor to create new "rows" for adding new categories dynamically. Although there are no errors displayed when I run the program, the intended functionality is not achieved. I have tried making some modifications but it see ...

Experience a seamless transition to the next section with just one scroll, allowing for a full

I've been attempting to create a smooth scroll effect to move to the next section using Javascript. However, I'm encountering issues with the window's top distance not being calculated correctly. I'm looking to have the full screen div ...

What is the method for retrieving the IDs of checkboxes that have been selected?

I attempted running the following code snippet: <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="text/javascript" src="http://static.jstree.com/v.1. ...

Every time I attempt to create a detail page for a table, I am consistently greeted with an error message

Error: Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /var/www/2909kher/entabell/detaljer.php on line 23 <!doctype ...

Use CSS alignment to combine both the profile picture and title on a webpage

Is there a way to seamlessly integrate a profile picture with text (title) on my tumblr theme? My main challenge lies in getting the alignment right. Additionally, I want it to look good in responsive view. If the title becomes too long, it should wrap un ...

Dynamically setting the IMG SRC attribute with the base64 result of a FileReader for file input

Looking for a little guidance on something new, I'll keep it brief because I'm sure it's just some small detail I'm overlooking... Starting with an image like this, where currentImage is the initial existing image path; <img src="{ ...

Is there a problem with addEventListener returning false?

What does keeping the third parameter as false in the line below signify? var el = document.getElementById("outside"); el.addEventListener("click", modifyText, false); ...

Slideshow through each item using Typescript and Angular8

I came across a solution in this carousel on by one link, but I'm struggling to work with the jQuery code even though I have JQuery installed in my project. For example: const next = jQuery(this).next(); I am looking to convert the JQuery code from ...

What is the best way to include a subscript (small letter) beneath a word using html and css bootstrap 5?

Is it possible to add a small letter (sub) below a word in HTML and CSS? I have included a screenshot for reference. I want to display "Max 100, Min 1" just like shown in the image. Here is my code: <input type="text" class="textarea" ...

Exploring the process of integrating absolute paths within a global SCSS file in a VueJS project

The webpack configuration in my vue.config.js file looks like this: const path = require("path"); module.exports = { pluginOptions: { 'style-resources-loader': { preProcessor: 'scss', patterns: [ "./src/style ...

By default, the sidebar is open on desktop devices while closed on mobile devices

I am struggling to figure out how to set my sidebar/navigation content, using Bootstrap, to be expanded by default on desktop and closed by default on mobile with the icon only showing on mobile devices. Despite multiple attempts, I cannot seem to make thi ...

Instructions for extracting the href value from an anchor tag using JavaScript within a specified string

How can I retrieve the href value of the last anchor tag in the provided content string using pure JavaScript, excluding jQuery? var contents = '<div id="content"><a href="http://www.okhype.com/wp-content/uploads/2016/12/ruffcoin-made-in-aba ...

The hyperlink within the Angular component seems to be unresponsive and is difficult to click on

I attempted to click on the user's profile link, but nothing happens. It seems impossible to interact with it. Here is the code snippet: JavaScript ViewUserProfile(user) { this.router.navigate([user.username]); if (this.currentUser.usernam ...

Adding a gap between the Bootstrap navbar and jumbotron for better spacing

Upon examining the Bootstrap example provided at: http://getbootstrap.com/examples/navbar/ I noticed there is a gap between the jumbotron and the navbar. After delving into the example's CSS, I found that disabling this rule (twice): .navbar { ...

I'm having trouble figuring out how to perfectly center this div on all types of devices

As someone who is new to css, I have been struggling to center these divs in the middle of the page across all devices despite searching extensively online and trying various solutions without any success. Check out my code below: Snippet: :after, :be ...

Zoom out the slider when scrolling

Take a look at this link and as you scroll down the page, notice how the image transitions to iPhone. Can anyone provide insight on how this effect is achieved? ...

Modify the style of a webpage through JavaScript

Need help with calling a JS event based on button presses and changing CSS font styling accordingly for each button? Check out the code snippet below: body { background-image: url("back2.jpg"); background-size: 100% 100%; } ...

Is it possible for me to convert the contents of a <div> into a rasterized image when printing?

I have been using jquery.printElement.js to print a custom calendar table that I created. The functionality inside a div is mostly working as expected, but I am facing some challenges with the CSS. Despite passing along all necessary .css files, my cells a ...