Home > Blockchain >  How to add more html elements below a video background that overflows into the navigation bar?
How to add more html elements below a video background that overflows into the navigation bar?

Time:04-04

*{
  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" >
        <img src="https://img.icons8.com/ios-glyphs/30/000000/menu--v1.png" alt="menu"/>
      </label>
      <label >SnowWarrior</label>
      <ul>
        <li><a href="#">Home</a></li>
        <li> <a href="#">Shop</a></li>
        <li> <a href="#">Contact</a></li>
      </ul>
    </nav>

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

    <section></section>

    <div >
      <span>Just saying</span>
    </div>
    
  </body>
</html>

In the attached image, which is actually a video I'm asking how to add text and other HTML elements below the video.

The video overflowing into the navbar is by choice since that is what I'm trying to achieve. However, when I try to add more div elements with text in there, it shows up behind the video instead of below the video. I'm very new to HTML and CSS (just dived into these two days ago) so I may be doing some things wrong here. But I would be glad if someone could point the right thing out to me.

Edit: Does anyone know how to embed a video into an HTML so it shows on StackOverflow?

CodePudding user response:

This would be my approach:

Using modern layout algorithms such as flexbox&grid rather than absolute positioning hell. Here I have a header with the nav and video as children. The header is a grid where the nav is explicitly set to take up the top section and the video explicitly told to take up the full grid.

Smaller components use flexbox to flex along a single axis, and when out of room, wrap onto a new line to allow the website to be responsive on small screen widths, removing the need for media queries here.

If you don't understand something and want me to update this answer to explain it, drop a comment.

* {
  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 >
    <img src="https://source.unsplash.com/random/800x400">
  </div>
</header>
Just saying

CodePudding user response:

This is because you're using position:fixed for everthing at the top, which then sadly makes your next element not care about its existance.

Simply put, if you put position:fixed, and then simply add an div with no position defined, they will not relate to eachother. As I do not know how you wish this to work I cannot fix the code for you, hence I will have to simply inform you about this and hopefully you'll be pointed in the direction you asked for - check position out in some css tutorials.

Display:flex is a good place to start.

  • Related