Show concealed elements above everything else

I've encountered an issue with my custom dropdown list as it displaces other elements when it appears. I want it to overlay on top of everything else, similar to the default select behavior.

Despite trying to set position: relative; and z-index:100;, I haven't been able to achieve the desired result.

For reference, here's the fiddle link: https://jsfiddle.net/vaxobasilidze/Lcztc8gc/

$('body').on('click touchend', '#typeSelect', function() {
  $('#typeDropDownList').css({
    'display': 'list-item'
  });
});

$('body').on('click touchend', '#typeDropDownList li', function() {
  var value = $(this).text();
  $('#typeSelect').text(value);
  $('#typeDropDownList').toggle();
});
#typeSelect {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid black;
  background-repeat: repeat;
  background-position: 300px;
  width: 353px;
  padding: 5px;
  line-height: 1;
  border-radius: 4px;
  box-shadow: 1px 1px 1px rgba(255, 255, 255, 0.1);
  -webkit-appearance: none;
  outline: none;
  color: #b8c0c8;
  width: 100%;
  cursor: pointer;
}

#typeSelect li {
  width: 100%;
}

#typeDropDownList {
  margin: 0;
  padding: 0;
  line-height: 1;
  -webkit-appearance: none;
  outline: none;
  color: #b8c0c8;
  width: 100%;
  border-radius: 3px;
  box-shadow: 0 2px 2px rgba(0, 0, 0, 0.26);
  display: none;
  position: relative;
  z-index: 100;
}

#typeDropDownList li {
  list-style: none;
  margin: 0 auto;
  padding: 0;
  border-top: 1px solid rgba(0, 0, 0, 0.7);
  background-repeat: repeat;
  background-position: 300px;
  padding: 5px;
  width: 100%;
  cursor: pointer;
}

#typeDropDownList li:first-child {
  border-top: none;
  border-top-left-radius: 3px;
  border-top-right-radius: 3px;
}

#typeDropDownList li:last-child {
  border-bottom-left-radius: 3px;
  border-bottom-right-radius: 3px;
}
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="settingsDiv">
    <table style="width: 100%;">
        <tr>
            <th colspan="2">Adapter 0</th>
        </tr>
        <tr>
            <td class="adapterInput" colspan="2" style="text-align: center;">
                <ul id="typeSelect">
                    <li>--- Choose type ---</li>
                </ul>
                <ul id="typeDropDownList">
                    <li>--- Choose type ---</li>
                    <li>DVB-S</li>
                    <li>DVB-S2</li>
                    <li>DVB-T</li>
                    <li>DVB-T2</li>
                    <li>DVB-C</li>
                </ul>
            </td>
        </tr>
        <table id="adapterInputContainer">
            <tr>
                <td>Frequency:</td>
                <td class="adapterInput">
                    <select>
                        <option value="S">DVB-S</option>
                        <option value="S2">DVB-S2</option>
                        <option value="T">DVB-T</option>
                        <option value="T2">DVB-T2</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>Inversion:</td>
                <td class="adapterInput">
                    <select>
                        <option value="AUTO">AUTO</option>
                        <option value="ON">ON</option>
                        <option value="OFF">OFF</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>Voltage:</td>
                <td class="adapterInput">
                    <select>
                        <option value="13">13</option>
                        <option value="18">18</option>
                        <option value="OFF">OFF</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td></td>
                <td class="adapterInput">
                    <input type="submit" style="float: right;">
                </td>
            </tr>
        </table>
    </table>
</div>

Answer №1

#customDropDownList {
  margin: 0;
  padding: 0;
  line-height: 1;
  -webkit-appearance: none;
  outline: none;
  color: #b8c0c8;
  width: 100%;
  border-radius: 3px;
  box-shadow: 0 2px 2px rgba(0, 0, 0, 0.26);
  display: none;
  position: absolute /*relative*/ ;
  z-index: 100;
  background: #fff; /* or any other color */
}

Answer №2

Adjust the positioning to absolute and apply a background color to your div. The transparent background allows the content beneath the custom dropdown to show through.

#typeDropDownList {
    margin: 0;
    padding: 0;
    line-height:1;
    /*box-shadow: 1px 1px 1px rgba(255,255,255,0.1);*/
    -webkit-appearance:none;
    outline:none;
    color: #b8c0c8;
    width: 100%;
    border-radius: 3px;
    box-shadow: 0 2px 2px rgba(0,0,0,0.26);
    display: none;
    position: absolute; // update this line
    z-index: 100;
    background:#f3f5f6; // add this line
}

See the demo here

Answer №3

To prevent visibility issues, consider changing the position of typeDropDownList to absolute and adding a background color.

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

Having trouble getting an HTML form to work when making a PHP and Ajax request

I am trying to validate an HTML form using Ajax to prevent the browser from loading the page. Ideally, when a user enters their first name, it should display above the HTML form. However, I am encountering an issue where it is not showing up as expected... ...

Adjust date by one day using the Datetimepicker tool

I have been attempting to adjust the date of my input by one day either forward or backwards, but I seem to be stuck and not making any progress. Take a look at my code: function function backDay() { var date = $('input#datetimepicker').va ...

The utilization of media within the meta in Next.js is not allowed

Recently, I came across an interesting article about PWAs on web.dev. The article discusses color schemes and at one point, they talk about it in detail, I'm currently working with Next.js and decided to try implementing the following code snippet: & ...

What is the best way to set a default value for a date input field?

I am in the process of developing a form that enables users to modify the information on the form, with the initial values of the form appearing as defaults. Despite setting my variable as the value, it does not display. All other default values are visib ...

The response time feature appears to be malfunctioning within Mockjax

How can I simulate a long response time using Mockjax? Despite setting the responseTime to 20 seconds, my ajax call is still being executed immediately when the page loads. Any suggestions on how to fix this issue? To isolate potential sources of error, ...

Uploading Images Dynamically with Ajax and jQuery in PHP

[Resolved Previous Issue] Recently, I obtained an image upload script that utilizes Ajax and jQuery. My goal is to restrict the maximum number of uploads to just 8 images. Any suggestions or advice would be greatly appreciated. Source of Download: ...

Is the data missing in the initial request?

After creating a function that returns an object with mapped values, I encountered an issue. The second map is undefined the first time it runs, causing my vue.js component to display data from the first map but not the cutOff value. Strangely, when I re ...

Stop the animated fun with Jquery Play

I've created a code snippet for fading testimonials: function rotateTestimonials() { $("#test-rotator .roter:hidden:first").fadeIn(500).delay(1000).fadeOut(500, function() { $(this).appendTo($(this).parent()); rotateTestimonials(); }).mouse ...

Tips for retrieving a parameter from the oncomplete attribute of an a4j:jsFunction tag

Is it possible to access a parameter for an <a4j:jsFunction> in the oncomplete="" attribute without using the action="" attribute and assingTo="" of <a4j:param>? <a4j:jsFunction name="refreshTableFilter" render="table,scroller" execute="@fo ...

How can I efficiently transfer information between AngularJS modules?

Angular offers the flexibility of creating independent Modules that can be reused in various parts of your application. Imagine having a module dedicated to managing lists, which you want to use across your entire application and populate in different ways ...

Animate a jumping figure using jQuery

Is it possible to create an animation of a person jumping from the bottom of the screen to the top, with the scroll bar following them? I have my doubts but would love to know if it can be done. If you want to see what I mean, check out this PDF: http:// ...

The removeAttribute function has the ability to remove the "disabled" attribute, but it does not have the capability to remove

When it comes to my JavaScript code, I have encountered an issue with two specific lines: document.getElementsByName('group')[0].removeAttribute('disabled'); document.getElementsByName('group')[0].removeAttribute('checke ...

Customize the font size in Bootstrap 5 using REM units

When it comes to setting font sizes for easier calculations in REM values, I currently use this approach: html { font-size: 62.5%; } body { font-size: 1.6rem; } /* 16px */ However, Bootstrap 5 uses the root value (which is typically set at 62.5%) to calc ...

Can we switch the country name to the database name in Jvector?

I've successfully implemented the Jvectormap application and it's functioning as expected. When I click on a country, it displays the name of that country. I have established a simple database for specific countries. Through AJAX, I've conn ...

Incorporating Bootstrap's Inline Design Elements

I am having trouble aligning a series of elements horizontally using bootstrap as shown in the example image below: Whenever I add the "form-control" class to the input element, it gets pushed down below the other elements. I have experimented with differ ...

Display a partial form in Rails using Ajax

There is a form displayed in the image below: Next, I aim to render this partial from an ajax call, specifically from .js.erb. However, I am unsure how to pass an object to f from the partial. Take a look at the image below for reference: Is there a way ...

Rendering React.js components as children of DOM elements

Trying my hand at creating a custom Map component includes the task of designing a unique Map Annotation. Here's an example of how a MapAnnotation component appears in the render function: <MapAnnotation title='Annotation' latitude={ 12.3 ...

Attempting to render a container within a hidden div and then make it visible results in an error

There appears to be an issue with ExtJS 6 regarding a bug. The problem can be replicated with minimal code in this online demo. In the code snippet below, we have a hidden div: <div id="btn"></div> <div style="display:none" id="outer_contai ...

Is it feasible to access a service instance within a parameter decorator in nest.js?

I am looking to replicate the functionality of Spring framework in nest.js with a similar code snippet like this: @Controller('/test') class TestController { @Get() get(@Principal() principal: Principal) { } } After spending countless ho ...

Create a prototype class in NuxtJS Vue

What is the correct way to set a class to prototype in Vue NuxtJS? I have created a plugin Here is my nuxt.config.js file: plugins: [ { src: "~/plugins/global.js" }, ], The global.js file contains: import Vue from "vue"; import CustomStore from "dev ...