Utilizing z-index for an overlapping effect in the Bootstrap grid system

I'm facing an issue with a div that displays a map across all 12 columns of the grid, but with a height of only 50vh. When I try to add two more divs below it, they end up overlapping. The mapDiv has a 'z-index:0', while my navbar has 'z-index:1'. Can someone help me identify the mistake? I've already attempted adding z-index values to the other two divs with no success.

     .mapDiv {
        position: absolute;
        z-index: 0;
        background-color: black;
        height: 50vh;
        width: 100%;
    }
    
    .formDiv {
        z-index: 0;
        background-color: black;
        height: 50vh;
    }
    
    .addressDiv {
        z-index: 0;
        background-color: crimson;
        height: 50vh;
    }
    .navbar
    {
       z-index:1;
       position:absolute;
    }
    <div class="container-fluid">
    <div class="row">
        <div class="col col-md-12 mapDiv" id="maps">
            <div class="img-fluid map-res">
                <script>
                    var map;

                    function initMap() {
                        var myLatLng = {
                            lat: 0
                            , lng: 0
                        };
                        var map = new google.maps.Map(document.getElementById('maps'), {
                            zoom: 16
                            , center: myLatLng
                            , mapTypeControl: true
                            , mapTypeControlOptions: {
                                style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR
                                , position: google.maps.ControlPosition.TOP_RIGHT
                            }
                        , });
                        var marker = new google.maps.Marker({
                            position: myLatLng
                            , map: map
                            , title: 'title!'
                        });
                    }
                </script>
                <script src="https://maps.googleapis.com/maps/api/js?key=API&callback=initMap" async defer>
                </script>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col col-md-6  formDiv"></div>
        <div class="col col-md-6   addressDiv"></div>
    </div>
</div>



 

Answer №1

Placing an element in absolute position means that it is removed entirely from the typical flow of the page layout, resulting in each element being positioned from the top left corner of the page.

When an element is positioned inside a relative container, it becomes absolute to the parent container.

In your situation, removing the position: absolute property or creating a parent container with position: relative will solve the issue.

Answer №2

.formDiv,
.addressDiv {
    position: relative;
}

When it comes to positioning elements using CSS, a positioned absolute element will look for the top most position: relative element. If no such relative position is found, it will default to absolute positioning based on the document structure.

If you want more information on this topic, check out the following links:

Z-Index Relative or Absolute?

Discover What No One Told You About Z-Index

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

MUI CSS: Mastering image manipulation

My MUI React Component features a Card that contains an image and buttons <Card key={index} className="xl:w-[350px] w-[310px] max-h-[450px]"> <img src={meme.url} className="center bg-cover" alt="" /> <Box cl ...

What are the best practices for utilizing intro.js effectively on mobile devices?

Description When using introjs on mobile devices with a screen width of less than 600px, the tooltip ends up covering the element. When I hold the device horizontally, the tooltip adjusts its position accordingly. I attempted to apply custom CSS to the too ...

How can I use jQuery to submit a form that has been removed from the document?

Having a popup with a form inside, the issue arises after clicking "save" and the popup disappears. As a workaround, an attempt was made to clone it using var form = $(this).clone();, followed by calling form.submit() but unfortunately, this method did n ...

Struggling with creating a responsive page design using Bootstrap to fit all screen sizes

Seeking advice on optimizing my Vue.js landing page for small screens. Bootstrap documentation was helpful but struggling to make it look clean and presentable on tablets and smartphones. Any tips or suggestions on how I can modify the layout for better ...

Display or conceal checkboxes according to the elements in an array

After just starting to delve into Angular and javascript, I've been racking my brain for the past couple of days. I have this table in html where I need to display checkboxes based on certain conditions. Each row consists of 5 checkboxes, and what is ...

Using jQuery to apply both class and font styles to HTML elements and then returning the modified HTML

I have received HTML text that requires the addition of a Bootstrap class after identifying specific tags. The string may contain multiple tags, and I need to insert a font tag with importance. For example, suppose I have the following string: var temp = ...

ASP.NET MVC does not automatically refresh when changes are made to the CSS file

Currently, I am diving into the world of Bootstrap 4 within an ASP.NET MVC project, exclusively making changes to the index.cshtml file in JetBrains Rider. However, I've encountered a strange issue that has me stumped. Each day, when I begin writing ...

Attempting to create a slider utilizing jQuery

I'm currently working on creating a slider using jquery. I have downloaded the cycle plugin for the slider and included it in my file. The slider consists of 7 pictures. Below is the code I am using, can someone please help me identify any issues? &l ...

Using AJAX and jQuery, the result is retrieved and inserted into a <div> element

Having trouble populating a DIV with the result of a simple GET request using AJAX and jQuery. What could be causing the issue? <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"> </script> <scrip ...

Using Javascript to create a radio button group

Is there a way to trigger an alert message when all radio buttons are checked as 'no'? I currently am only able to check each radio button individually. //The method I currently know $('#attraction1').change( function(){ if ($(this ...

Utilizing MUI for layering components vertically: A step-by-step guide

I am looking for a way to style a div differently on Desktop and Mobile devices: ------------------------------------------------------------------ | (icon) | (content) |(button here)| ----------------------------------------- ...

Is there a way to extract all the data values starting with "data-" from the selected input fields in HTML5 and compile them into an object?

Looking for a way to automate input values: <input class="form" type="checkbox" name="item1" data-value="{ 'item1':'selected', 'price': 100 }" checked="checked"> <input class="form" type="checkbox" name="item2" data- ...

Is there a way to adjust the position of the scrolling bar to be closer to the post area?

I was exploring this page (http://noahsdad.com/state-fair-texas-2011/) and noticed a scrolling sidebar to the left of the content area. I'm looking to adjust it so that it is closer to the content area. Any suggestions on how to achieve this? Thank y ...

Utilizing jQuery or JavaScript to convert a PHP return value into an array for use in JavaScript

Is there a way to retrieve a JavaScript array from a PHP return value? For example, if a PHP script called 'makeArray.php' returns "first", "second", "third" (without the single quotes), how can I use this array in JavaScript to alert "second"? ...

Allow iframe to be edited within jsfiddle

I have a question that I need to ask soon, but first I need an editable iframe in jsfiddle. It's working fine on my local machine, but not on jsfiddle. I believe it's because of the frames being used? On my local machine, I use: setTimeout(&apo ...

Image selection plugin in Cordova not functioning properly

Currently, I am attempting to select multiple images from the gallery using the cordova-imagePicker plugin. It's worth noting that my project uses Cordova rather than the Ionic framework. Below is the code snippet I have implemented: <script type ...

Hide buttons on click in textarea

I am working on a user input interface which includes a textarea for typing, along with a cancel and submit button. Is there a way to show the cancel and submit buttons only when the user clicks inside the textarea? (I prefer using vanilla JavaScript inst ...

Video playback in IE8 is not supported by mediaelement.js

I have gone through all the questions posted here, but none of them have solved my issue. Currently, the video loads and plays in Chrome, Safari, FF, and IE9, but not in IE8, which is the browser I need to support. You can see the page here. Despite tryi ...

Unfold an HTML element and reveal a sneak peek of its content with the aid of JQuery

I need a way to organize and display a set of 5 lines of text vertically. Specifically, I want them arranged like this: 1) Line one 2) Line two 3) Line three 4) Line four 5) Line five However, I have a special requirement where only the first ...

Custom JSX element failing to include children during addition

I have created a unique component in JSX, like this: const CustomComponent = ({content}) => { return <div className={content}></div>; } I am using it as follows: <CustomComponent content={"xyz"}> <p>Some additio ...