Ensure that the "select" dropdown menu remains a constant size

One section of my Android app, powered by JQuery Mobile, displays a table with a combobox. The issue arises when selecting the option with a very long text, causing the combobox to expand and show half of the table off-screen.

My goal is to set the combobox to a fixed initial size that adjusts dynamically based on the screen resolution. Does anyone have a solution for this problem?

Answer №1

Here's a demo you can check out: http://jsfiddle.net/Gajotres/HZAnz/

All you need is some simple CSS styling:

.ui-select, #sl_bnd, #sl_bnd option {
    width: 200px !important;
}

You also have the option to use percentages:

.ui-select, #sl_bnd, #sl_bnd option {
    width: 80% !important;
}

If you want to target a specific select element:

#custom-select .ui-select, , #sl_bnd, #sl_bnd option {
    width: 200px !important;    
}

The key is to make use of !important to override default styles.

If you only need to adjust the width of the options:

#sl_bnd, #sl_bnd option {
    width: 200px !important;    
}

Answer №2

For those with a responsive mobile site,

Feel free to visit http://jsfiddle.net/yeyene/vDeKq/2/

To ensure its adaptability, adjust the width dynamically.

$('#sl_bnd').css({
    'float':'left',
    'width': ($(window).width()-$('#c_label').width()-20)+'px' 
});

If you are using JQM, rest assured this issue has been addressed.

View the DEMOhttp://jsfiddle.net/yeyene/vDeKq/4/

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

Glitchy/Crazy CSS3 Animations

Currently, I am developing a website at . One of the features I have implemented is CSS3 transitions for route changes, but this feature only works in Chrome. Here's how the animation works: I apply the .preanimate class to rotate the phasing out di ...

Optimize Material-UI input fields to occupy the entire toolbar

I'm having trouble getting the material-ui app bar example to work as I want. I've created a CodeSandbox example based on the Material-UI website. My Goal: My goal is to make the search field expand fully to the right side of the app bar, regar ...

Cannot utilize Map within each loop

Below is the less code snippet: @threshold:{ a:50; b:200; }; @themes:{ a:red; b:blue; }; .mymixin(@name,@color,@thrshld){ //do-something } each(@themes,{ .mymixin(@key,@value,@threshold[@key]); }); Upon executing the code, an error message ...

Navigating through each segment

I'm currently working on a website with sections that are set to be 100% height of the window, but at least 800px tall. My goal is to implement a smooth scrolling functionality where one scroll moves the view from section to section. However, if the ...

Exploring the wonders of jQuery Ajax within Yii

I am developing a custom shop application and I have a query. In my project, the implementation of Ajax in Yii involves: <?php echo CHtml::ajaxLink( '', array("cart/add/id/$item->id"), array( ' ...

The best method to transfer numerous objects to a web method using an ajax call

How do I send 2 objects in ajax? One object contains a list of records. I've tried the following code but it's not working. Can someone help me out? var obj = {}; obj.ChangeDetails = ""; obj.ChangeInformation = ""; obj.ChangeVersion = ""; obj.C ...

aligning divs in a horizontal distribution is ineffective when the divs become fixed in place

When distributing divs horizontally equally, issues arise when these elements are attached without spaces in between (particularly in Chrome and Firefox). For instance: http://jsfiddle.net/pdelorme/au9ouko0/ HTML : <div class="ul"> <div class=" ...

I desire a three-column layout where the middle column will expand in width if columns 1 and 3 are vacant

I have a three-column layout designed without using tables. <div id="main"> <div id="left"></div> <div id="content"></div> <div id="right"></div> </div> This is the CSS code: #left {width: 200px;fl ...

Utilize CSS properties to pass as arguments to a JavaScript function

Is there a way for me to make my CSS animation functions more efficient? I have similar functions for different properties like height, width, and left. Can I modify the function below to accept a CSS property argument instead of hardcoding height? Window ...

Choosing the perfect interface between JQuery Mobile and a Java backend for a mobile web application

Currently, we are in the process of developing a mobile web app to replace an older Java web app - specifically, just the database from that app. We have chosen not to migrate the original app completely due to its outdated custom ORM solution and Struts ...

Refresh HTML table when database is updated

My panel has a user table which is populated using the following snippet of Php code : <html> <body> <div id="order_table"> <table> <thead> <tr> <th>Name</th> < ...

Dynamically updating fields in PHP using jQuery's passed variable

In my web application, I have a selection of locker numbers available in a dropdown list that is populated from MYSQL/PHP. My goal is to display each locker's combination and location when a user selects a locker number from the dropdown list on the s ...

How come when I click on the edit button, the selected data's model doesn't appear in the dropdown menu as I would like it to?

this is the function in my controller public function getModel($make_id = null) { $make_id = request()->make_id; $carsmodel = CarModel::where('make_id', $make_id)->orderBy('model', 'ASC')->get(); return re ...

Switch up the text when the image link is being hovered over

Is there a way to change the text color of the "a" tag when it is not wrapping the img link? <li> <a href="# WHEN I HOVER THIS IMG LINK I WANT A TAG BELOW TO CHANGE COLOR"> <img alt="Franchise 16" src="#"></img> < ...

Is it possible to achieve 100% screen height by combining a fixed height div with a stretchy height div?

I have a design concept that I'm trying to bring to life. I'm struggling with figuring out how to add another "stretchy div" to the layout. I want this second div to expand to fill all remaining vertical space on the screen without causing it to ...

Tips on maintaining the parent's scope in CoffeeScript while making an AJAX call

I need to iterate through an object in CoffeeScript and make an AJAX call for each item in the object using jQuery. However, I'm facing an issue with losing the reference to the initial context in the callback function of the AJAX call. The context al ...

Why does the loading image appear prior to clicking the submit button?

I am having trouble with displaying a gif loading message properly on my website. When the submit button is clicked, I want the loading message to appear and then disappear once the data has finished loading. Currently, the loading message shows up when t ...

What could be causing my PHP login page to malfunction?

I'm facing an issue with my code where nothing happens when I click the submit button. This is puzzling as the same code worked perfectly fine in a previous project. I'm unable to pinpoint where the problem lies. Here's the HTML form: < ...

How can I generate a hyperlink for a specific directory on Github Pages?

If I have a repository with one file and one folder, as listed below: index.html folder The folder contains another file named: work.html My goal is to access the folder website using only the link: username.github.io/repositoryname/folder Instead ...

Guide on restricting the character count and displaying the leftover characters using PHP with Ajax

I've been working on implementing a feature to display the remaining characters in a PHP AJAX call. I was successful using JavaScript, but I'm having trouble doing it with AJAX in PHP. Can someone provide assistance? <script type="text/javasc ...