Ways to superimpose one div on top of another

I'm experimenting with overlaying two divs on top of a main div using CSS properties like position absolute and top. However, I'm uncertain about the correct approach to make this responsive.

The Video SDK will insert the video stream into the main div, but it seems to have a black background that I'd like to eliminate. If I can't find another solution, my last resort is to manually hide the black sections at the top and bottom using additional divs and CSS.

Here's an example - the current view is contained in a single div, but I want to get rid of the black background at the top and bottom of the video card https://i.sstatic.net/LL0Al.jpg

My desired outcome looks like this -

https://i.sstatic.net/yn0si.jpg

I've added two divs, one at the top and one at the bottom, with a gray background. But I suspect this isn't the best way to achieve my goal. How can I ensure it stays intact even when resizing the browser window?

Code -

<div id="root" style="position: relative; display: block; max-width: 100%; text-align: center; margin-top: 10%; height: 80vh; margin-right: auto; margin-left:auto">
                <!-- The Video SDK will inject the video stream here -->
</div>
            <div id="hide_top" style="position: absolute;height: 12vh;width: 76vw;background: gray;top: 20%;"></div>
            <div id="hide_bottom" style="position:absolute;height: 15vh;width: 76vw;background: gray;top: 54%;"></div>

Answer №1

To create an overlay effect with CSS, you can utilize the position property along with the z-index property to stack one div on top of another. The z-index property controls the vertical stacking order of positioned elements like those with absolute, fixed, or relative positioning.

Let's explore a practical example to illustrate this concept:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>CSS Overlaying One DIV over Another DIV</title>
        <style> 
            .container {
              width: 200px;
              height: 200px;
              position: relative;
              margin: 20px;
            }

            .box {
              width: 100%;
              height: 100%;            
              position: absolute;
              top: 0;
              left: 0;
              opacity: 0.8;  /* for demonstration purposes */
            }

            .stack-top {
              z-index: 9;
              margin: 20px; /* for demonstration purposes */
            }
        </style>
    </head>
    <body>
        <div class="container">
            <div class="box" style="background: red;"></div>
            <div class="box stack-top" style="background: blue;"></div>
        </div>
    </body>
</html>

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

What could be causing the error I'm encountering while attempting to utilize Array.includes as the function for Array.filter in my JavaScript code?

During a recent javascript project, I attempted something like the following code snippet. To my surprise, it did not work and instead produced an error message. const test = [1, 2, 3, 4]; const something = [1, 2, 3, 4, ,5, 6, 7, 8].filter(test.includes) ...

The input '{ data: InvitedUser[]; "": any; }' does not match the expected type 'Element'

I'm currently facing a typescript dilemma that requires some assistance. In my project, I have a parent component that passes an array of results to a child component for mapping and displaying the information. Parent Component: import { Table } fr ...

What could be the reason for the sudden failure of my jQuery + AJAX functionality?

As a novice in JavaScript/jQuery/AJAX, I have a suspicion that the issue lies in some typo that I may have overlooked. Everything was working perfectly, but when I made some edits, the hide() + show() methods stopped functioning (I tested it on both Firefo ...

Vue JS: Breathing Life into Your Elements

Incorporating Vue-Router and Vuex, I have successfully implemented a Users Profile Component that fetches user information by extracting the username parameter from a router-link. For example, <router-link :to="{name: 'user', params: { usernam ...

Unlock the Potential of Bootstrap5 Carousel: Mastering Icon Movement

I'm utilizing the carousel from Bootstrap 5, and here is the image. https://i.sstatic.net/dpmjf.jpg The previous and next icons are overlapping with the text. I would like to reposition them, if possible, just above the upvote/downvote buttons. Howe ...

When it comes to utilizing jQuery for the mobile view, how many jQuery libraries are recommended for optimal performance?

I'm currently constructing a website using ROR, and for the mobile view, I've implemented the mobile_fu gem. The designer provided me with a design for the mobile view that includes various jQuery sliders, players, image sliders, drop-down menus ...

Dynamically loading JSON content in an Angular application based on the user's selected item

I am utilizing a table that is populated through a REST request to http://localhost:8080/Sprint002b/restpatent/. Upon clicking on an item within the table, which can be found in list-patents.htm, a separate container appears in patent-item.htm. This conta ...

issue encountered during resource provider setup

Below is my code snippet where I'm attempting to populate a table using ngResource in a RESTful manner. However, when I include configuration directives, I encounter an uncaught object MINERR ASST:22 error. var app = angular.module('infra&apo ...

Need to know how to retrieve the li element in a ul that does not have an index of 2? I am aware of how to obtain the index greater than or less

I'm looking to hide all the li elements except for the one with a specific index. I've written some code to achieve this, but I'm wondering if there's a simpler way using jQuery. While jQuery provides methods like eq, gt, and lt, there ...

Showing PHP array in the JavaScript console

I have a straightforward AJAX script that sends 3 variables to an external PHP script. The external script then adds them into an array and sends the array back. I want to output this array in the JavaScript console to check if the variables are being pass ...

Instead of using a computed getter/setter, make use of mapState and mapMutations to simplify

Currently, I am syncing a computed value to a component and using a computed setter when it syncs back from the component. I'm wondering if there is a more concise way to replace a computed getter/setter with mapState and mapMutations. How can this b ...

What are the reasons behind loading failures and the subsequent failure to resolve promises?

Here is a snippet of code that is part of a larger directive: var imageArray = []; for (var i = 0; i < $scope.abbreviations.length; i++) { imageArray[i] = new Image(); imageArray[i].src = $scope.abbreviations[i].img ...

Issue with bootstrap tooltip visibility within a specific div container

I am trying to align a div tag to the right, but when I add a Bootstrap tooltip to the left of it, the tooltip is not appearing. <div class="container-fluid"> <div class="row"> <div id="map" style="width: 100%; height ...

- The click function is failing to work after an ajax call [Potential event delegation problem]

I have a webpage where I update the contents of an unordered list using $.get() every 5 seconds. The issue I am facing is that the click function for the list items is not working properly. Even though the list items are being updated correctly, there se ...

Tips for updating values in an Angular model and pushing it to an array with the specified index

I am currently facing an issue with my Angular Model as I attempt to add it to an array in order to generate repeated fields. The purpose of this array is to then be looped through in order to create HTML fields within a component. However, during the proc ...

Transferring a Query between Domains with the Help of JavaScript

It is necessary to develop a function that generates a query based on the user's input of "Test" in an INPUT on Site A (SiteA.com) and then redirects to Site B within the same window, passing along the query (SiteB.com/search.aspx?k=test). Code snipp ...

Display the Currently Searched Value with Select2

I am currently utilizing the Select2 framework along with an ajax call in my project. I have successfully implemented it, but I am facing an issue where the current search value is being displayed as a selectable option even when there are no search result ...

Ways to delete specific data and insert a new row into a Jquery data table without disrupting the remaining rows

I have a dataset with 100 rows of information, and I need to remove specific data based on ID and add new rows for those IDs. I also want to be able to edit the existing rows based on their IDs. Below is the code snippet I am using: oCustomization : { ...

Refining Flask-Generated Table Content with jQuery Filters

I'm currently attempting to render a Jinja2 template that showcases an HTML table and enables dynamic filtering to search through the table content. Unfortunately, I'm facing issues with getting the search functionality to work properly. While th ...

Ways to identify the active anchor within an li element

Below is the code snippet I am currently working with: <li> <a href="<?php echo base_url()?>home/promos/call" class="promo-call active-call"></a> </li> <li> <a href="<?php echo base_url()?>home/promos/text ...