What is the best way to showcase a div on top of all other elements in an HTML page?

As a newcomer to html and css, I have successfully created a div that contains city names. The issue I am currently facing is when I click on a button to display the div, it gets hidden behind the next section of my page. Take a look at the image below for reference:

What I actually want is for the div to be displayed over the section below it, rather than hiding behind it. For a clearer idea of what I mean, you can visit askme.com and click on the 'rest of india' dropdown button. Here is the HTML code I am using:

<!--start SearchBox section-->
        <section id="searchbox" style="background:white">
            <div class="container" style="margin-top:0px;">


              <div class="row">

                    <div class="col-lg-12">


               <form style="">
                    <center>
                            <div id="SearchBoxBorder" style="background:white;border-style:soli;border-radius:5px;margin-top:20px;width:800px;">
                            <table id="mytable" >
                                    <td style="width:300px;background:white;">
                                       <center> <div class="form-group">
                                                <input type="text" class="form-control" id="exampleInputEmail1" placeholder="I am looking for"
                                                    style="border-width:5px;background:white; margin-top:17px; margin-left:15px; margin-right:10px;width:300px;
                                                    border-style:solid;border-width:5px;border-color:#eee;font-family:Arial,Helvetica,sans-serif;height:42px; font-size:18px;">
                                        </div></center>
                                     </td>

                                     <td style="width:50px ;text-align:right;background:white;"> <center><strong> in</strong></center>    </td>

                                     <td style="width:400px;background:white;">
                                     <center>
                                             <div class="input-group" style="position: relative;">
                                                   <input type="text" class="form-control" placeholder="in locality"
                                                    style="border-width:5px;background:white; margin-top:2px; margin-left:10px; margin-right:20px;width:;">
                                                   <div class="input-group-btn" >
                                                            <button type="button" class="btn btn-default dropdown-toggle"  data-toggle="dropdown" id="dropdownBtn" 
                                                             style="background:white;border-top-width:5px;border-right-width:5px;border-bottom-width:5px;border-left-width:1px;
                                                             border-color:#eee;height:42px;border-radius:0px;text-align:center;color:black; margin-right:20px;margin-top:2px;">Select<span class="caret"></span></button>

                                                             <!--City dropdown -->
                                                                    <div class="SearchCities" id="dialog" title="Basic dialog" >

                                                                            <div id="outer" style="">



                                                                                        <div id="innerLeft" style="">
                                                                                            <h5 >North India:</h5>
                                                                                            <ul class="city" type="none">
                                                                                                    <li><a>Delhi</a></li>
                                                                                                    <li><a>Agra</a></li>
                                                                                                    <li><a>Shrinagar</a></li>
                                                                                                    <li><a>Noida</a></li>
                                                                                                    <li><a>Himachal</a></li>
                                                                                                    <li><a>Patna</a></li>
                                                                                            </ul>

                                                                                        </div>

                                                                                        <div id="innerRight" style="">
                                                                                            <a class="close">&times;</a>
                                                                                            <h5>West India:</h5>
                                                                                            <ul class="city" type="none">
                                                                                                    <li><a>Mumbai</a></li>
                                                                                                    <li><a>Pune</a></li>
                                                                                                    <li><a>Nashik</a></li>
                                                                                                    <li><a>Kolhapur</a></li>
                                                                                                    <li><a>Osmanabad</a></li>
                                                                                                    <li><a>Ahamdabad</a></li>
                                                                                            </ul>
                                                                                        </div>


                                                                            </div><<!--/outer-->
                                                                        </div><<!--/SearchCities-->


                                                             </div><<!-- /btn-group -->
                                                   <button type="button" class="btn btn-primary" style="margin-right:20px;"><i class="icon-search" style="font-size:20px"></i>  Search</button>
                                             </div><<!-- /input-group -->
                                           </center>         
                                     </td>

                            </table>
                        </center>
                    </form>

    </div><<!--/col-lg-12-->
</div><<!--/row-->
    </div><<!--/end of container-->
</section>
<<!--End of SearchBox section-->

In addition, here's the CSS snippet I'm using to attempt displaying the div:

.SearchCities {
  float: right;
  position:absolute;
  margin-top:3px;
  top: 100%;
  right:20px;

}

I appreciate any help or suggestions on how to achieve the desired outcome. Thank you in advance.

After adding .searchCiries{z-index:1;}, the output looks like this:

I aim to prevent the city names from overflowing outside the container div. Any corrections or advice would be greatly appreciated.

Answer №1

If you want to control the stacking order of elements in CSS, simply include a z-index value such as: z-index:100

Answer №2

For optimal display, consider adding the following CSS rule to your div's class:

    z-index: 9990;

By setting the z-index property to 9990, you ensure that your div will be brought to the front of the stack, unless the z-index value of other elements exceeds 9990 (note that the maximum value is 9999).

Check out more about z-index here: http://www.w3schools.com/cssref/pr_pos_z-index.asp

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

Dealing with a Jquery/Javascript Dilemma

As a beginner in query/javascript, I am encountering an issue with the code below when trying to calculate gross value and tax amount based on the net amount entered by the user. The input is expected to be a double amount, with gross and VAT amounts defin ...

Gulp fails to generate a CSS file after compiling Sass to CSS

Recently, I've been having trouble compiling my sass file to css. Even though it was working fine before and I haven't made any changes, now my CSS file is empty. Below is the task I am trying to accomplish: gulp.task('sass', function ...

Issue encountered during Node.js installation

Every time I attempt to install node js, I encounter the following errors: C:\Users\Administrator>cd C:/xampp/htdocs/chat C:\xampp\htdocs\chat>npm install npm WARN package.json <a href="/cdn-cgi/l/email-protection" class ...

Is there a way to use fetch() to automatically redirect a user after logging in?

I'm currently working on a node.js application using express, and I am in the process of creating a login form for my users. I want to include a Javascript file that utilizes fetch() to send a POST request to my API for user authentication. However, I ...

Accessing Child Properties in Parent Component using Typescript

New to the world of Typescript! Imagine having a component called TitleSubtitle that consists of both a Title and a Subtitle component. The Title component comes with props: interface TitleProps { text: string; } The Subtitle component also has props ...

Issue with the transparency of a model in three.js

Exploring my journey with Three.js, I have been actively engaging in online communities like Stack Overflow to enhance my skills. This project serves as my inaugural experiment with loading OBJ and MTL files. However, an issue has surfaced - certain parts ...

Managing User Sessions in Meteor

Is there a way to dynamically retrieve and set the pageTitle for my Meteor app using jQuery or any other method? I've attempted to achieve this by creating a session when a specific div class is present on the page, but it doesn't seem to be work ...

I could really use some assistance with this script I'm working on that involves using ($

Using Ajax for Form Submission: $.ajax({ url: 'process.php', type: 'post', data: 'loginName=' + $("#loginName").val() + 'loginPass=' + $("#loginPass").val(), dataType: 'json', success: func ...

"Sorting functionality in Amcharts with dynamic movement of the div as the chart scroll bar is used

After exploring the question discussed here, I discovered that using li wasn't the most suitable option for me. Therefore, after further investigation and following the guidance provided in the example here, I successfully managed to create a customiz ...

The PKIJS digital signature does not align with the verification process

Explore the code snippet below const data = await Deno.readFile("./README.md"); const certificate = (await loadPEM("./playground/domain.pem"))[0] as Certificate; const privateKey = (await loadPEM("./playground/domain-pk ...

Exploring the application of URL parameters in HTML code

How can I use URL parameters retrieved with Javascript in my HTML? <script> var url_string = window.location.href; //window.location.href var url = new URL(url_string); var c = url.searchParams.get("name"); console.log(c); </script> I am tryi ...

Troubleshooting: Image Not Displaying in Twitter Bootstrap Theme

I'm new to using bootstrap and I'm encountering an issue where my image is not showing up. Strangely, the default background image is appearing even though I have not referenced it in the HTML or CSS files. View my code here ...

What is the process for interacting with a Node.js Web API using an Angular JS API?

Seeking assistance with converting HTML into JADE format, encountering issues with {{record.name}} not functioning correctly. This is preventing the fetching and printing of values. Below are the complete file details: Directory view can be seen here. JS ...

Click to reveal sliding menu bar

Trying to create a sliding menu bar (.top-bar) that activates when clicking an arrow (#hide), causing the arrow to also slide up and switch from an up arrow to a down arrow. Here is my unsuccessful attempt: $(document).ready(function(){ $("#hide").c ...

Are you experiencing empty boxes instead of Glyphicons in Bootstrap 3?

Having some trouble using Glyphicons with Bootstrap 3. I've noticed that a few of them aren't displaying properly. For instance, when trying to use these three glyphicons, the first one doesn't seem to show up correctly (appears as an empty ...

Utilize Multidimensional Arrays in HTML

I have a pair of fields called url and id. <input type='url' name='data[web][url]'><input type='number' name='data[web][id]'> <input type='url' name='data[web][url]'><input t ...

The data is successfully being logged in the console but is not appearing on the page in Reactjs

I'm currently working on Reactjs with the Next.js framework. I'm trying to fetch data using axios, but the data isn't showing up on the page. However, when I check the console.log in the getStaticProps section (in blogs), the data is there. ...

Understanding the reasons behind 'undefined' res.body in Express

Why does the response body show as undefined in Express? How can I access the response body properly? Is something going wrong here? import {createProxyMiddleware} from 'http-proxy-middleware' import bodyParser from 'body-parser' impor ...

Issues with Retrieving Nested Arrays

I am encountering an issue with an object within an array and I am looking to specifically display that as an array. data1 const data1 = [ { "id": "01", "info": "fefef", "sub": "hieei&qu ...

JavaScript code that activates several hovering elements

I am a beginner in the world of JavaScript and I'm attempting to create a simple function that will activate multiple div hover effects. I have tried various approaches so far, but I believe this code is closer to the solution. Any assistance from som ...