Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

CSS video background

Helo.

I have implemented a video background to a div on my website.

As you will see from the code below it´s in a div class called main. I would like to add a grid layout within this div to add my content.
But as you see, the logo is placing itselfe below the background and not as content with the video as a background.

What am I doing wrong? Hope someone can help.

Here´s my HTML:
HTML:
<!doctype html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>RS Design</title>
        <link rel="stylesheet" href="css/reset.css" media="screen" />
        <link rel="stylesheet" href="css/main.css">
     
     </head>

<body>
<div class="container">
   
    <div class="header">
       
        <div class="nav">
            <div class="topBotomBordersOut">
                <a href="#">HOME</a>
                <a href="#">SERVICES</a>
                <a href="#">ABOUT</a>
                <a href="#">CONTACT</a>
            </div>
        </div>            
       
    </div>

   
    <div class="main">

   
        <video id="background-video" autoplay loop muted>
                <source src="video/animated_bg_2.mp4" type="video/mp4">
                </video>

                <div class="main-left">
                <img src="images/logo.png"  width="436" height="281" alt=""/>
                </div>  

    </div>
   
   
    <div class="footer">
   
    </div>

       
</div>
   

</body>
</html>


Her´s my CSS
CSS:
.container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;

}

.header {
    width: 100%;
    position: absolute;
    background-color: rgba(27,61,95,0.85);
    height: 35px;
    line-height: 35px;
    border-bottom: 3px solid #c3944b;

}

.main {
    flex-grow: 1;
    margin-left: auto;
    margin-right: auto;
    max-width: 1920px;
    padding-left: 20px;

}

.footer {
    border-top: 3px solid #c3944b;
    background-color: #314c68;
    height: 250px;
}

/* NAV */

.nav{
    margin: auto;
    max-width: 1920px;

}

.nav a {

    color: #FFF;
    text-decoration: none;
    font: 14px Raleway;
    margin: 0px 0px 0px 20px;
    padding: 10px 10px;
    position: relative;
    z-index: 0;
    cursor: pointer;
}

/* NAV ANIMATION */

.topBotomBordersOut a:before, div.topBotomBordersOut a:after
{
    position: absolute;
    left: 0px;
    width: 100%;
    height: 2px;  
    background: #c3944b;
    content: "";
    opacity: 0;
    transition: all 0.3s;
}

div.topBotomBordersOut a:before
{
    top: 6px;
    transform: translateY(10px);
}

div.topBotomBordersOut a:after
{
    bottom: 7px;
    transform: translateY(-10px);
}

div.topBotomBordersOut a:hover:before, div.topBotomBordersOut a:hover:after
{
    opacity: 1;
    transform: translateY(0px);
}

/* BACKGROUND */

#background-video {
    margin-top: 0px;
    align: right;
    z-index: -1;
}

Here´s my RESET
CSS:
@import 'https://fonts.googleapis.com/css?family=Raleway';

*,
*::before,
*::after {
  box-sizing: border-box;
}

* {
      margin: 0;
      padding: 0;
      font: inherit;
}

html {
      box-sizing: border-box;
    font-size: 16px;
    color-scheme: dark light;
}


body, h1, h2, h3, h4, h5, h6, p, ol, ul {
    height: 100%;
    margin: 0;
    padding: 0;
    font-family: 'Raleway', sans-serif;
    color: #FFFFFF;
    background-color: #e0e2e4;
    min-height: 100vh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
   
}

h1{
    font-weight: bold;
    font-size: 4rem;
    line-height: 1;

}

h2{
    font-weight: bold;
    font-size: 2rem;
    line-height: 1;

}

h3{
    font-weight: bold;
    font-size: 2rem;
    font-style: italic;
    line-height: 1;
}


a:link { text-decoration: none; }
a:visited { text-decoration: none; }
a:hover { text-decoration: none; }
a:active { text-decoration: none; }

h1{
    font-weight: bold;
    font-size: 4rem;
    line-height: 1;

}

h2{
    font-weight: bold;
    font-size: 2rem;
    line-height: 1;

}

h3{
    font-weight: bold;
    font-size: 2rem;
    font-style: italic;
    line-height: 1;
}

/* responsive images/videos */
img, picture, svg, video {
  display: block;
  max-width: 100%;
}

p, h1, h2, h3, h4, h5, h6 {
  overflow-wrap: break-word;
}

ol, ul {
    list-style: none;
}

a {
  text-decoration: none;
}

input, button, textarea, select {
  font: inherit;
  -webkit-user-select: auto;
}

input, button, textarea, select {
  font: inherit;
}
 
<div class="main-left"> does not have its own styling. It should have a z-index value and a position property.

Neither .main nor #background-video have position properties.

I would start there.
 
<div class="main-left"> does not have its own styling. It should have a z-index value and a position property.

Neither .main nor #background-video have position properties.

I would start there.
Thanks for your help. I´m getting somewhere now :blush:

Two questions!
1. is there a way to make the grid expand/contract vertically within the <div class="main"> ? I would like it to fill that vertical space.

2. I have a video background. But in my reset.css I have set a background color to the body and it shows up behind the paragraph text and blocks the video. Is there way around this?

Here´s the example pic, html and css:

example_1.jpg

HTML:
<!doctype html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>RS Design</title>
        <link rel="stylesheet" href="css/reset.css" media="screen"  />
        <link rel="stylesheet" href="css/main.css">
     
     </head>

<body>
   
   
   
<div class="wrapper">
   

   
    <div class="header">
       
        <div class="nav">
            <div class="topBotomBordersOut">
                <a href="#">HOME</a>
                <a href="#">SERVICES</a>
                <a href="#">ABOUT</a>
                <a href="#">CONTACT</a>
            </div>
        </div>            
       
    </div>

   
    <div class="main">
       
        <video id="background-video" autoplay loop muted>
        <source src="video/animated_bg_2.mp4" type="video/mp4">
    </video>
       
        <div class="container">
   
            <div class="content-1">
                    <img src="images/logo.png" alt="Logo"/>
                    <h1>Ronny Syvertsen</h1>

            </div>  

                <div class="content-2">
                    <img src="images/ronny_placeholder.png" width="570" height="904" alt=""/>
           </div>

            <div class="content-3">
                    <p>Pellentesque habitant morbi tristique senectus<br> et netus et
                       malesuada fames ac turpis<br> egestas. Vestibulum tortor quam,<br>
                       feugiat vitae, ultricies eget, tempor sit amet, ante.<br>Donec eu libero
                        sit amet<br> quam egestas semper.</p>
            </div>
       
        </div>

   
    </div>
   
    <div class="footer">
       
    </div>

       
</div>
   

</body>
</html>

MAIN CSS:
CSS:
/* BACKGROUND */

#background-video {
    position: absolute;
    margin-top: 0px;
    align: right;
    z-index: -1;
}

img{
  max-inline-size: 100%;
  block-size: auto;
}


.wrapper {
    display: flex;
    flex-direction: column;
    min-height: 100vh;



}

.header {
    width: 100%;
    position: absolute;
    background-color: rgba(27,61,95,0.85);
    height: 35px;
    line-height: 35px;
    border-bottom: 3px solid #c3944b;

}

.main {
    flex-grow: 1;
    margin-bottom: 0px;
    margin-left: auto;
    margin-right: auto;
    max-width: 1920px;
    padding-left: 20px;
    padding-right: 20px;
}

.container{
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    margin-top: 50px;
    margin-bottom: 0px;
    margin-left: 10px;
    margin-right: 10px;
    width: 100%;

}

.content-1{


}

.content-2{


}

.content-3{


}

.footer {
    border-top: 3px solid #c3944b;
    background-color: #314c68;
    height: 250px;
}

/* NAV */

.nav{
    margin: auto;
    max-width: 1920px;

}

.nav a {
    color: #FFF;
    text-decoration: none;
    font: 14px Raleway;
    margin: 0px 0px 0px 20px;
    padding: 10px 10px;
    position: relative;
    z-index: 0;
    cursor: pointer;
}

/* NAV ANIMATION */

.topBotomBordersOut a:before, div.topBotomBordersOut a:after
{
    position: absolute;
    left: 0px;
    width: 100%;
    height: 2px;  
    background: #c3944b;
    content: "";
    opacity: 0;
    transition: all 0.3s;
}

div.topBotomBordersOut a:before
{
    top: 6px;
    transform: translateY(10px);
}

div.topBotomBordersOut a:after
{
    bottom: 7px;
    transform: translateY(-10px);
}

div.topBotomBordersOut a:hover:before, div.topBotomBordersOut a:hover:after
{
    opacity: 1;
    transform: translateY(0px);
}

RESET CSS:
CSS:
/*/**/*/@import 'https://fonts.googleapis.com/css?family=Raleway';

*,
*::before,
*::after {
  box-sizing: border-box;
}

* {
      margin: 0;
      padding: 0;
      font: inherit;
}

html {
      box-sizing: border-box;
    font-size: 16px;
    color-scheme: dark light;
}


body, h1, h2, h3, h4, h5, h6, p, ol, ul {
    height: 100%;
    margin: 0;
    padding: 0;
    font-family: 'Raleway', sans-serif;
    color: #FFFFFF;
    background-color: #e0e2e4;
    -webkit-font-smoothing: antialiased;
   
}

h1{
    font-weight: bold;
    font-size: 4rem;
    line-height: 1;

}

h2{
    font-weight: bold;
    font-size: 2rem;
    line-height: 1;

}

h3{
    font-weight: bold;
    font-size: 2rem;
    font-style: italic;
    line-height: 1;
}


a:link { text-decoration: none; }
a:visited { text-decoration: none; }
a:hover { text-decoration: none; }
a:active { text-decoration: none; }



/* responsive images/videos */
img, picture, svg, video {
  display: block;
  max-width: 100%;
}

p, h1, h2, h3, h4, h5, h6 {
  overflow-wrap: break-word;
}

ol, ul {
    list-style: none;
}

a {
  text-decoration: none;
}

input, button, textarea, select {
  font: inherit;
  -webkit-user-select: auto;
}

input, button, textarea, select {
  font: inherit;
}
 
Try something like this to see how your layout reacts.

CSS:
.container {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: 1fr;
    margin-top: 50px;
    margin-bottom: 0px;
    margin-left: 10px;
    margin-right: 10px;
    width: 100%;
    align-items: stretch;
}

.content-1, .content-2, .content-3 {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

You may want to split the content elements up, out of your personal preference or if one needs its own property separate from the others.

For the background issue, you can stop the inheritance by giving the element its own background color property, background-color: transparent;
 
Thank you! That helped alot!
But is there a way to make <div class="container"> cling to the bottom of <div class="main"> so it sticks to the bottom even when I shrink the window size? I have tryed align, margin an so on, but with no luck.

example_2.jpg
 
But is there a way to make <div class="container"> cling to the bottom of <div class="main"> so it sticks to the bottom even when I shrink the window size? I have tryed align, margin an so on, but with no luck.
Try adding height: 100%; to each element to ensure they are trying to take up all available vertical space.
 
Are you sure that grey is actually the .main element? In the CSS there doesn't seem to be a property setting the .main element to a grey background colour.
If you are sure of it, and height: 100% isn't working, try adding min-height: 100%; to the .container element.
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom