Ways to place a png image on top of a video background

How can I overlay a PNG over my background video without it appearing behind?

I attempted to use z-index, but the video disappears when changing the position from relative to absolute or fixed. Here is the HTML and CSS code:

<div id="page2">
    <video autoplay loop muted id="video">
        <source src="Images/KeyboardVideo.mp4">
        <source src="Images/KeyboardVideo.webm">
    </video>

    <div id="servicelogo"><img src="images/htmlcssjs.png"></div>
</div>


/* CSS Document */

* {margin: 0; padding: 0;}

body{
    font-family: arial,helvetica;
    color: black;
    text-align: center;
}

h1{
    font-size: 6em;
    padding-top: 305px;
    opacity: 0.8;
}

p{
    font-size: 2em;
}


#wrapper {
    position: fixed;
    height: 80px;
    width: 100%;
    background-color: black; 
    z-index: 500;
}

#nav {
    height: 80px;
    width: auto;
    float: right;
    list-style: none;
    position: relative;
    margin-right: 100px;
    z-index: 500;
}

#nav li {
    height: 80px;
    width: 100px;
    float: left;
    font-family: sans-serif;
    font-weight: bold;
    color: white;
    padding: 0px 15px 0px 15px;
    text-align: center;
    line-height: 80px;
    font-size: 20px;
}

#video {
position: relative;
width: auto;
min-width: 100%;
height: auto;
background: transparent url(images/Nature2.jpg) no-repeat;
background-size: cover;
z-index: -1
}

#servicelogo img{
    position: relative;
    height: 40%;
    width: 40%;
    margin-top: 8%;
    opacity: 0.8;
}

#page2 {
    width: 100%;
    max-height: 100%;
    overflow: hidden;
    top: 0;
    right: 0;    
}

a {text-decoration: none;}

/* unvisited link */
a:link {
    color: white;
}

/* selected link */
a:active {
    color: #7f8c8d;
}

/* visited link */
a:visited {
    color: white;
}

/* mouse over link */
a:hover {
    color: #7f8c8d;
}


#page1  {background-image: url(images/Nature1.jpg); z-index: -1;}
#page3 {background-image: url(images/Nature2.jpg);}
#page4 {background-color: #2ecc71;}

Answer №1

After some trial and error, I was able to solve the issue! Below is the CSS code that did the trick:

#video { 
  position: fixed;
  top: 50%;
  left: 50%;
  min-width: 100%;
  min-height: 100%;
  width: auto;
  height: auto;
  z-index: -100;
  transform: translate(-50%, -50%);
}

#servicelogo img{
position: relative;
height: 40%;
width: 40%;
margin-top: 8%;
opacity: 0.8;
}

#page2 {
    width: 100%;
    max-height: 100%;
    overflow: hidden;
    top: 0;
    right: 0;    
}

Answer №2

Here is a sample snippet you can use:

.videoitem {
  position: relative;
  overflow: hidden;
  
  width: 560px;
  height: 315px;
}

.videoitem-cover {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  /*** opacity: 0; ***/
  background: yellow;
  transition: 250ms opacity ease-out;
  line-height: 315px;
  text-align: center;
  -webkit-pointer-events: none;
  pointer-events: none;
}

.videoitem:hover .videoitem-cover {
  opacity: 1;
}
<div class="videoitem">
  <div class="videoitem-embedd"><iframe width="560" height="315" src="https://www.youtube.com/embed/zdkWGsnzTXk" frameborder="0" allowfullscreen></iframe></div>
  <div class="videoitem-cover">Hovering</div>
</div>

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

Is there a way to make Chrome ask to save a password within an HTML form?

I'm having trouble getting a basic email/password HTML form to prompt Chrome to save the password. Despite following examples, it's not working for me. Here is my code: <form name="loginForm" action=""> E-Mail:<br><input ...

How can I execute a Python script on an HTML webpage by clicking a button?

Below is the HTML code I have written: <script> function goPython(){ $.ajax({ url: "MYSCRIPT.py", context: document.body }).done(function() { alert('finished python script');; ...

Hide the burger menu when a link is clicked

Is there a way to make my Bootstrap burger menu automatically close when the user clicks on a menu link, rather than having to click on the burger itself? I've tried using some JavaScript code but it ends up disabling the burger menu entirely. Can any ...

What are the top techniques for designing with Angular 2 Material Design?

As a newcomer to angular 2 material design, I have noticed the primary, accent, and warn classes that apply specific colors to elements. Are these the only styling options available in Angular Material 2? Are there other classes that can be utilized for cu ...

jQuery Slider not appearing on the page

I am attempting to incorporate the Basic jQuery Slider into my website. Below is the code I have used: For HTML file: <div id="slides"> <ul class="bjqs"> <li><a href="somelink"><img src="someim ...

I'm having trouble getting Firefox to recognize the percentage height set on table rows. Any suggestions for a workaround?

The goal is to set the height of the first row to 70% of the screen. To prevent the scrollbar from appearing on the entire webpage, overflow has been set to auto within the div of the first row. This solution functions correctly on Chrome and IE, however, ...

The remove() function is failing to eliminate the element from all parent elements with the same class

I have a bunch of Wordpress posts. When the browser size is reduced to a certain point, I must relocate one specific element from each post to another element as per the design requirements. Here is the code I am using to iterate through each post and mov ...

Ways to prevent an empty iframe from triggering a load event upon injection

I have implemented a technique where I am using an empty frame to handle pseudo-asynchronous form submission. This involves referencing the frame's name attribute in the form's target attribute, allowing the form's action URI to resolve in t ...

Capturing a variety of input values from a form and storing them in an array

I have a form with several input fields like this: <input type="text" name="name[]" value=""> <input type="text" name="name[]" value=""> <input type="text" name="name[]" value=""> I am attempting to submit the form and store those value ...

php$insert new field into mysql table using form insertcell

How do I insert a column in MySQL? I am struggling with the insertCell form. I have tried but I can't seem to add a MySQL column using my JavaScript code with PHP. I am familiar with Php PDO, but this seems difficult to me. Can someone guide me on ho ...

Automatic Submission based on Checkbox Selection

Creating a user-friendly interface for project admins is my goal, but I am encountering difficulties in displaying all tasks. The data is retrieved from the database and put into a table, with each task having a status represented by a binary value - 1 f ...

Tips for preventing the bootstrap modal from disappearing during auto postback in asp.net

I am currently using vb.net in my asp.net project along with Bootstrap 4. Within a modal, I have two dropdown lists. The goal is for the second list to be sorted based on the user's selection from the first list. However, I encountered an issue where ...

Using PHP to create multiple div elements and then concealing them all

I'm having an issue with the hide feature not working. My intention is to hide each dynamically generated div and gain control over them, but the problem seems to lie in the div id incrementing. Any assistance would be greatly appreciated! <?php $ ...

CSS: Preserve HTML elements and only conceal the text within an <a> tag

Inside an "a" element, there's an image followed by text as a link. I'm looking to only hide the text of the link without affecting the display of the image. <a href="https://www.example.com/page"> <img src=" ...

Blurring the Background with CSS

Greetings! I'm attempting to achieve a background blur effect similar to the image shown. I am curious if this can be accomplished using only CSS3 or if JavaScript & Jquery are necessary for implementation: If CSS alone is sufficient, how can I ens ...

retrieve the parent frame's request URL

I am faced with the task of writing a JSP code that retrieves the getRequestURL() of the parent frame (the URL shown in the address bar) from a child frame. However, when I attempt to do this, I only obtain the URL of the child frame. Is there anyone who ...

management in the same row or in the following row fashion

Looking to achieve a specific behavior for a label and control: If the screen width is less than X, the label and control should be on different rows with the control expanding to full width. If the width is equal to or greater than X, the label and cont ...

Obtain the identifier of a div within nested HTML components by utilizing jQuery

How do I retrieve the id of the first div with the class: post, which is "367", using jquery in the given HTML code: <div id="own-posts"> <span class="title">Me</span> <div class="posts_container"> <div class="post"& ...

JavaScript and HTML have encountered an Uncaught TypeError: The property 'addEventListener' cannot be read because it is null

Having an issue here. Whenever I try to play sound from an image, I encounter an error. Uncaught TypeError: Cannot read property 'addEventListener' of null Here is my HTML code: <html> <head> <title>Music</title> < ...

Access to PHP script (IF) unattainable following a POST occurrence

I'm completely new at this. I am attempting to create a contact form using HTML5 and PHP mail function, but I am facing an issue with my form action pointing to contacto.php. After submitting the form, it seems to be skipping over the IF condition wi ...