How to overlay a video on top of an image using HTML and CSS

Hey, I need some help with creating a cool graphic for my website at . I want to have a video playing on the screen of a laptop image, and it should be responsive so it looks good on mobile too. Below is the CSS and HTML code that I've tried so far, but any advice or guidance would be greatly appreciated!

#laptop-panel {
        position: relative;
        width: auto;
        height: 625px;
        overflow: hidden;
    }

    #laptop-panel-tv {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: url('http://176.32.230.43/testdigitalmarketingmentor.co.uk/wp-content/uploads/2016/07/laptop-1000x728-trans.png') no-repeat center;
        z-index: 10;
    }

    #laptop-panel-content-overlay {
        position: absolute;
        top: 70px;
        width: 100%;
        height: 444px;
        z-index: 12;

    .embed-container {
        position: relative;
        padding-bottom: 56.25%;
        padding-top: 30px;
        height: 0;
        overflow: hidden;
        max-width: 100%;
        height: auto;
      }
.video-container {
    position: relative;
    padding-bottom: 56.25%;
    padding-top: 30px; height: 0; overflow: hidden;
}
 
.video-container iframe,
.video-container object,
.video-container embed {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}
<div id="laptop-panel">
    <div id="laptop-panel-tv"></div>
    <div id="laptop-panel-content-overlay">
    <div id="laptop-panel-content">
        <div class="embed-container">
            <div style="width:683px;" class="wp-video">
                <!--[if lt IE 9]> <script>document.createElement('video');</script> <![endif]-->

                <div class="video-container">
                    <iframe src="https://www.youtube.com/embed/BhEWkcyXYwg?rel=0&amp;controls=0&amp;showinfo=0" frameborder="0" allowfullscreen></iframe>
                </div>
            </div>
        </div>
    </div>
</div>

Answer №1

Are you open to using a setup like this? It can also boost your Youtube views.

    #laptop-panel {
        position: relative;
        padding-top: 25px;
        padding-bottom: 67.5%;
        height: 0;
    }
    #laptop-panel iframe {
        box-sizing: border-box;
        background: url(http://176.32.230.43/testdigitalmarketingmentor.co.uk/wp-content/uploads/2016/07/laptop-1000x728-trans.png) center center no-repeat;
        background-size: contain;
        padding: 11.7% 17.9% 15.4%;
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
    }
  <div id="laptop-panel">
        <iframe src="https://www.youtube.com/embed/BhEWkcyXYwg?rel=0&amp;controls=0&amp;showinfo=0" frameborder="0" allowfullscreen></iframe>
    </div>

Enjoy the coding process!

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

single-use date availability checker

I'm currently facing an issue with my code. It seems to be functioning correctly, but only for the first iteration. Let me explain further. If I select a date and time that is already in the database, it correctly displays "date unavailable". Likewis ...

No animated scrolling occurring

I have been struggling with this problem for a while now and despite having gone through 100 questions, I still can't find a solution as to why my code snippet is failing. Here is the jQuery code I am using: $("#readmore").click(function(event){ ...

Error in jQuery Bootstrap: "TypeError: 'undefined' is not a function when attempting to hide modal with jQuery('#myModal').modal('hide')"

I am having trouble manually closing a bootstrap modal view after an ajax request is completed in my application. I tried using jQuery('#myModal').modal('hide'); within the callback function: function(){ ...

What is the Solution for Adjusting the Dimmed Text Selection Shade in Safari? - CSS

Can someone help me with an issue I'm having on my website? I've been using CSS code to change the color of selected text, and it's working perfectly fine on every browser except for Safari. In Safari, the color appears darker than what I&ap ...

Having trouble with innerHTML.value functionality?

Recently, I've been delving into creating a JavaScript program that fetches Wikipedia search results. Initially, everything seemed to be working fine as I was able to display the searched item using the alert() method. However, for some reason, it now ...

Splitting the page into four sections with a unique H layout using CSS styling

Attempting to create an H page layout: body { background-color: grey; background-size: 100%; background-repeat: no-repeat; } html, body { height: 100%; margin: 0px; } .a { float: left; width: 25%; height: 100%; border: 1px solid blue ...

Facing a problem with displaying Leadbolt HTML ads?

I'm currently working on incorporating leadbolt HTML ads into my Android app, which utilizes a WebView to display HTML for the user interface. I have been provided with this simple tag from my leadbolt control panel: <script type="text/javascript ...

Uncovering concealed data in job listings by utilizing BeautifulSoup

Hey there! Currently, I am enrolled in a python course and our assignment for today involves extracting job listings from this website: I have attached a screenshot of the HTML related to this task here: python jobs f12 This is what I have managed to com ...

Creating distinct web addresses for various sections of vue.js pagination

I've implemented pagination using vue.js for my website's gallery. However, I'm facing an issue where the URL doesn't change when navigating through pages and upon page refresh, it always resets to page 1. My goal is to have the URL ref ...

Customize Bootstrap styling based on screen size changes

I am curious to learn how I can adjust the CSS of my website in Bootstrap based on different screen sizes. I want to change text sizes and images, but I'm unsure about how to do it. Thank you for any guidance. Here is a snippet of my code: <!DOCT ...

Adding text values to an HTML form action

I am working on a form that includes a text input field and a submit button. Is there a way for me to add the value of the text box to the form action URL? For example, can I dynamically change the action attribute to something like: action="https://www. ...

Form validation on the client side is not occurring, and the form elements cannot be edited

Having trouble with client-side form validation. Specifically, I need to ensure that passwords match in my registration form. Below is the JavaScript code snippet I'm using: $(document).ready(function(e) { $("#reg-form").submit(function(event) { ...

Tips for preventing line breaks in CSS while adjusting zoom levels on a webpage

While adjusting the zoom level on the page, I noticed that the text breaks and separates onto another line. The first quick link appears fine, however there seems to be an issue with the second and third quick links as well as the lorem text. Apologies f ...

Tips for speeding up your website by preloading versioned files in HTML

Tools like Google Lighthouse and PageSpeed recommend preloading important requests using <link rel=preload> to enhance website performance. When it comes to static files with unchanging filenames, the process is straightforward. However, how can I ...

What is the best way to implement CSS style modifications when I am specifically on one of the two pages?

Every single page on my website has a unique class in the body tag. I've been able to successfully edit elements on a specific page using the following code: .page1 .someClass p{ color: #cccccc } How can I achieve the same effect of changing the ...

Display a notification in the browser every hour using JavaScript

As a newcomer to JavaScript, I am embarking on the task of creating a basic web application that involves setting a timer and triggering a popup message when it reaches zero. Update: It is important to note that the user may not have this webpage actively ...

Show MaterialUI Dialog in fullscreen mode

I'm just starting out with React and Material-UI, and I'm trying to figure out how to print my current dialog. The issue I'm running into is that I can't seem to find a way to set the Dialog to full screen for printing while keeping it ...

Why isn't the alignment and background color of my navigation menu (nav) functioning properly?

Having trouble with my navigation styling - the alignment and background color only show up when I remove the closing brace for the "nav" CSS. I have 2 different CSS stylings in place to center the nav items and add a background color, but something's ...

Using Jquery to animate content sliding off screen in both left and right directions

Looking for guidance on creating slide left and right content transitions similar to those found in apps instead of webpages. Can anyone provide insight on how to achieve this using JQuery? By clicking on the Left (<) or right (>) button, it should ...

Steps to crafting an image with a white box overlapping

Currently, I'm working on designing a white text box that includes both a title and content. My navbar and background image are already set up, so the next step is creating this new container. Is there anyone out there who could provide some guidance ...