Ways to change the row height of the dropdown list according to the information in the second column?

I utilized the selectMenu jQuery widget to create a dropdown list and then incorporated it into Angular to build a reusable dropdown component. The issue I am currently dealing with is related to the height adjustment of the columns within each row of the dropdown list. Specifically, the content in the 2nd column is causing the other two columns to not adjust dynamically when the content length increases. I am unsure of how to resolve this problem. The image below shows the dropdown list with the unadjusted row height.

https://i.sstatic.net/tLkvA.png

For reference, here is the link to the codepen page containing the example and code I used: Codepen Dropdown link. I attempted to fix this issue by applying display:table-cell; in the CSS file, but my efforts were unsuccessful. I would appreciate any suggestions on how to resolve this issue. Additionally, the desired output can be seen in the following image. https://i.sstatic.net/gdU87.png

Below is the code snippet.

$(function() {
  $.widget("custom.mySelectMenu", $.ui.selectmenu, {
    // code here
  });

  // additional code here
});
.ui-selectmenu-category {
  // CSS code
}

// more CSS code here
<html lang="en">

<head>
  <meta charset="utf-8>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Selectmenu - Custom Rendering</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>

<body>
  <label for="options">Select an Option:</label>
  <select id="options">
    <optgroup label="PREFERRED OPTIONS">
      <option data-short="L" data-price="$0.00">Standard Screw Adjustment</option>
      <option data-short="K" data-price="$0.00">Standard Screw Adjustment</option>
    </optgroup>
    <optgroup label="STANDARD OPTIONS">
      <option data-short="C" data-price="$5.00" >Tamper Resistant - Factory Set</option>
      <option data-short="K" data-price="$6.00" >Handknob</option>
    </optgroup>
    <optgroup label="ADDITIONAL OPTIONS">
      <option data-short="F" data-price="$4.00">Hex Head Screw with Locknut</option>
      <option data-short="G" data-price="$4.00">Hex Head Screw with Locknut</option>
      <option data-short="H" data-price="$4.00" >Hex Head Screw with Locknut</option>
    </optgroup>
  </select>
</body>

</html>

Answer №1

You have the ability to achieve this by utilizing the properties display:table and display:table-cell

$(function() {
  $.widget("custom.mySelectMenu", $.ui.selectmenu, {
    _renderMenu: function(ul, items) {
      var that = this,
        currentCategory = "";
      $.each(items, function(index, item) {
        var li, name, short, price;
        if (item.optgroup != currentCategory) {
          ul.append(
            "<li class='ui-selectmenu-category'>" +
              item.optgroup +
              "</li>"
          );
          currentCategory = item.optgroup;
        }
        li = that._renderItemData(ul, item);
        console.log(ul);
        name = li.text();
        short = item.element.data("short");
        price = item.element.data("price");
        console.log(li, short, price);
        li.prepend(
          $("<span>", {
            class: "short"
          }).html(short)
        );

        li.append(
          $("<span>", {
            class: "price"
          }).html(price)
        );
        if (item.optgroup) {
          li.attr("aria-label", item.optgroup + " : " + item.label);
        }
      });
    }
  });

  $("#options").mySelectMenu({
    width: 300
  });
  $("#options")
    .mySelectMenu("menuWidget")
    .addClass("overflow");
});
.ui-menu .ui-menu-item { 
  display:table; width:100%;
}
.ui-menu .ui-menu-item-wrapper {
    position: relative;
    padding: 3px 1em 3px .4em;
    border-width: 1px 0 1px 0;
    border-color: transparent;
    border-style: solid;
}
.ui-selectmenu-category {
  color: #5f5f5f;
  padding: 0.5em 0.25em;
  min-width: 290px;
}

.ui-selectmenu-category::after {
  content: "PRICE";
  float:right;
  padding-right: 40px;
}

.ui-menu-item .ui-menu-item-wrapper {
  display: table-cell;
  vertical-align:top
  padding: 1em 2px;
}


.ui-menu-item .ui-menu-item-wrapper.ui-state-active {
  margin: 0;
    border-width: 1px 0px 1px 0px;
    border-color: #cccccc;
    background-color: #e4ebf1;
    color: #000;
}

.ui-menu-item .ui-menu-item-wrapper.ui-state-active.short {
  color: #2e6d99;
  
}

.ui-menu-item div.ui-menu-item-wrapper {
  width: 290px;
  
}

.ui-menu-item .short {
  color: #2e6d99;
  font-weight: strong;
  width: 30px;
  padding-left: 0.5em;
  position:absolute;

}

.ui-menu-item .price {
  font-weight: strong;
  width: 75px;
  margin-right: -6px;
 
}


.overflow {
  height: 200px;
}
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Selectmenu - Custom Rendering</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>

<body>
  <label for="options">Select an Option:</label>
    <select id="options">
  <optgroup label="PREFERRED OPTIONS">
    <option data-short="L" data-price="$0.00">Standard Screw Adjustment dkjsahdksajd sdhsdl sdshad ;sldh sd;lsa d;lsajd</option>
    <option data-short="K" data-price="$0.00">Standard Screw Adjustment</option>
  </optgroup>
  <optgroup label="STANDARD OPTIONS">
    <option data-short="C" data-price="$5.00" >Tamper Resistant - Factory Set</option>
    <option data-short="K" data-price="$6.00" >Handknob</option>
  </optgroup>
  <optgroup label="ADDITIONAL OPTIONS">
    <option data-short="F" data-price="$4.00">Hex Head Screw with Locknut</option>
    <option data-short="G" data-price="$4.00">Hex Head Screw with Locknut</option>
    <option data-short="H" data-price="$4.00" >Hex Head Screw with Locknut</option>
  </optgroup>
</select>
</body>
</html>

Answer №2

An easy solution is to include the following code:

.ui-menu .ui-menu-item:not(.ui-selectmenu-category) {
  display: flex;
}

Answer №3

Make sure to include this line in your code: display: flex;

.ui-menu .ui-menu-item {
display: flex;
height: auto;
flex-direction: row;
margin: 0;
cursor: pointer;
list-style-image: 
}

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

Troubleshooting issues with Bootstrap Nav-pills functionality

I have encountered an issue with my navigation structure. I am using a main nav-menu and a secondary nav-menu within the same div. When I first enter the page, the "Profile" tab is correctly active by default. Then, when I click on "Test", it becomes activ ...

Retrieving information from a dynamically created HTML link地址

I was curious about whether Selenium is the sole library capable of extracting data from a table on a specific webpage, found here. While attempting to navigate these sites with bs4, I found that it only displayed the table headers without any data. It wo ...

What is the best way to use CSS to evenly lay out a group of dynamically generated buttons?

My Vue-generated buttons need to be evenly laid out on the bottom of the page, with equal space on the left and right. The mdui button style I am using has fixed width and height, so I have to decide between a single row for fewer buttons (less than three ...

Stop the Form from Submitting When Errors are Present

In the midst of explaining my issue, I must first share details about a form I'm developing. It's a Registration form where upon submission by clicking Submit, users won't immediately reach a Successfully Registered page. Instead, they' ...

left-floating div

I am currently working on designing a page that requires multiple columns to be displayed. The columns should float left and never appear stacked on top of each other. Ideally, I would like the columns to extend beyond the screen without a scrollbar, makin ...

Adding new elements to a div container

My goal is to populate a div element with items based on elements from an array. I need to duplicate an existing element on the page and append the new version to the div. Let me provide the code for better understanding: JavaScript: function apply(list ...

Attempting to transmit a pair of parameters from an HTML form through Flask (within a URL) in order to subsequently execute in a Python script

As a newcomer, I am working on a Python algorithm that requires two parameters obtained from an HTML form. Here is the snippet of my HTML code: <form action="result/"> <p><input class="w3-input w3-padding-16" method ...

Tips for customizing Material-UI Switch button appearance

Is there a way to remove the box-shadow on the thumb of the Switch button when it's disabled? I've tried various methods like adding the box-shadow in the switchBase and removing it from the thumb, but it affects the parent element as well. Anoth ...

Should I consider implementing Flexbox even if I need to cater to users still using IE9?

Currently, I am embarking on a fresh project centered around constructing a chat window. Typically, I would readily employ Flexbox for this endeavor; nevertheless, one of the stipulations for this project is to ensure compatibility with IE9. While I under ...

What is the best way to style these CSS elements within the stylesheet?

I'm currently working on customizing a navigation menu in DotNetNuke. Although my question primarily relates to CSS syntax. Can someone please provide guidance on how to style a class that resembles the following? <tr class="mi mi0-0 id58 first"& ...

To link circles vertically with a line and fill them with color when clicked, follow these steps:

I am looking to create a design similar to the image below using unordered list items. When a user clicks on a list item, I want the circle to fill with color. I have structured it by creating a div with nested list items and span elements. If a user click ...

Ensure that the tooltip remains visible within the confines of the page

In my Angular application, I have successfully implemented a versatile tooltip feature that goes beyond just displaying text. The tooltip is a div element that has the ability to contain various contents: .tooltip-master { position: relative; .tooltip ...

Exploring Checkboxes in Hypertext Markup Language

Can anyone advise on the proper HTML input attribute to limit user selection in a list of checkboxes? Specifically, I want users to select no more than three out of five checkboxes without using radio buttons. Please provide solutions using only HTML and n ...

Steps for setting a background image behind radio buttons

I am currently facing a challenge in adding a background image to a div that contains some radio buttons and updating it dynamically with Angular based on the current page. app.controller('thingCtrl', function ($scope, $rootScope, $routeParams ...

I found that the Angular checkbox was only allowing me to select one value at a time instead of

Hey there, I am currently working on an angular tickbox where I want to be able to tick multiple values. However, I am facing an issue where only the latest checkbox value is displayed instead of both English and German together. How can I populate data fr ...

The Google Map is unable to expand to fill the entire width of the column

I have exhausted all my efforts trying to troubleshoot this issue on my project's contact page. Currently, I have a layout with 3 rows containing columns within a Bootstrap 4 grid. The third row is supposed to display a Google Map within a column set ...

Replace the instances of "foo" with "bar" in the phrases "foo bar" and "bar foo."

Using a regular expression, I am able to locate specific words and then manipulate them in some way. For example: I want to surround all the words I find with <strong> tags: $string = 'Hello, there is foo, after there is bar but now I need fo ...

Attempting to execute Gulp 4 in order to convert SCSS files into CSS

After attempting to run Gulp to convert SCSS to CSS, the process appeared to be successful without any errors. However, I encountered a problem where no CSS files were generated in the target folder. I even tried changing the output path, but the issue per ...

Struggling to align a column within a container in HTML CSS, issues with CSS not functioning as expected

I have been attempting to vertically center the column within a container, but it keeps aligning to the left. Despite trying numerous CSS properties, I can't seem to get it right. Shrinking the width of the paragraph container to 650px or 70% doesn&ap ...

How can a JavaScript function be triggered by Flask without relying on any requests from the client-side?

I'm in the process of setting up a GUI server using Flask. The challenge I'm facing is integrating an API that triggers a function whenever there's a change in a specific Sqlite3 database. My goal is to dynamically update a table on the HTML ...