Troubleshooting the Problem of Uneven Heights in Bootstrap Columns

I am facing an issue with a dropdown inside a Bootstrap grid. When I click on the dropdown, the height of the row is not increasing as expected.

Can anyone guide me on how to achieve this?

HTML:

<div class="container">
    <div class="row">
        <div class="col-12"> 
            <select name="cars" id="cars">
                <option value="volvo">Volvo</option>
                <option value="saab">Saab</option>
                <option value="opel">Opel</option>
                <option value="audi">Audi</option>
            </select>
        </div> 
    </div>
</div>

CSS:

.row {
     border: 1px solid;
     height:auto;
 }

.col-md-4 .col-sm-8 .col-sm-4{
    border: 1px solid;
    display: block;
}

Current outcome:

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

Desired outcome:

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

Stackblitz demo

Answer №1

I'm not certain about the possibility of styling the traditional dropdown list to occupy space on the webpage. Therefore, I have presented an alternative solution that will meet your requirements using a custom dropdown.

Take a look at this:

// Fetch all necessary elements
const dropdownBtn = document.querySelector('.dropdown-btn');
const dropdownList = document.querySelector('.dropdown-list');

// Event listener for toggling the visibility of the dropdown list
dropdownBtn.addEventListener('click', () => {
  dropdownList.classList.toggle('show');
});

// Event listener for selecting an option
dropdownList.addEventListener('click', (event) => {
  if (event.target.tagName === 'LI') {
    const selectedOption = event.target.textContent;
    
    // Dropdown value
    const selectedOptionValue = event.target.getAttribute('value');
    
    // Display the selected option in the button
    dropdownBtn.textContent = selectedOption;
    
    // Hide the dropdown list after selection
    dropdownList.classList.remove('show');
  }
});
.row {
     border: 1px solid;
     height:auto;
 }

.col-md-4 .col-sm-8 .col-sm-4{
    border: 1px solid;
    display: block;
}

/* Basic styling for the dropdown container */
.custom-dropdown {
  position: relative;
  display: inline-block;
}

/* Styling for the dropdown button */
.dropdown-btn {
  padding: 10px 20px;
  background-color: #f2f2f2;
  border: 1px solid #ccc;
  border-radius: 5px;
  cursor: pointer;
}

/* Styling for the dropdown list */
.dropdown-list {
  position: relative;
  top: 100%;
  left: 0;
  list-style: none;
  padding: 0;
  margin: 0;
  display: none;
  background-color: #fff;
  border: 1px solid #ccc;
  border-radius: 5px;
}

/* Styling for the dropdown list items */
.dropdown-list li {
  padding: 10px 20px;
  cursor: pointer;
}

/* Show the dropdown list on hover/focus */
.custom-dropdown:hover .dropdown-list,
.custom-dropdown:focus-within .dropdown-list {
  display: block;
}
<div class="container">

    <div class="row">
        <div class="col-12">
          <div class="custom-dropdown" name="cars" id="cars">
          <button class="dropdown-btn">Select Option</button>
          <ul class="dropdown-list">
            <li value="volvo">Volvo</li>
            <li value="saab">Saab</li>
            <li value="opel">Opel</li>
            <li value="audi">Audi</li>
          </ul>
        </div>

        </div> 
    </div>
</div>

You can retrieve the dropdown value from the selectedOptionValue variable.

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

The issue encountered is a TypeError stating that it is unable to retrieve properties of an undefined value, specifically in relation to the 'imageUrl

When I include the following line of HTML code: <td> <img align="center" [src]="productByBarCode.imageUrl" /> </td> An error is thrown by the console: ERROR TypeError: Cannot read properties of undefined (reading &a ...

Unable to conceal adjacent radio buttons

My challenge is to use only HTML and CSS, without JavaScript, to show the first radio button with its label initially. When a user clicks on it, the second radio button and label should appear while the first disappears, and so on. I am struggling to ach ...

Bootstrap design malfunctioning in Firefox browser

view image description hereMy responsive web design site (built with Bootstrap 3) is functioning perfectly on Chrome, Edge, and Opera browsers. However, on Firefox, the grid layout initially loads correctly but then breaks after a second? view image descr ...

Having trouble loading CSS in an express view with a router

I am encountering an issue where I am unable to load my CSS into a view that is being rendered from a Router. The CSS loads perfectly fine for a view rendered from app.js at the root of the project directory. Below is my current directory structure, node_ ...

Conceal and reposition divs based on device with Bootstrap's responsive utilities

Utilizing Bootstrap to design a layout that adapts to desktop, tablet, and mobile screens. The desired output is depicted below: In order to achieve this, three divs were created: <div class="row"> <div class="col-md-3">Text</div> & ...

horizontal alignment of row content to the right in HTML

Trying to align a text and a small image horizontally to the right: <div class="row float-right"> <div class="title" >Stream Chat</div> <img src="~assets/chat.svg" /> </div> ...

Resolving Div Alignment Issues in Internet Explorer with jQuery CSS AddClass and RemoveClass

I've set up an HTML table with a hover highlight feature using jQuery and CSS. Here's how my hover event is structured: $('#' + element.id + ' tr:not(:first,[class="summary_row"])').die('mouseover mouseout').live(&a ...

Having trouble understanding how to create a continuous loop for a CSS animation within the KreatureMedia Layerslider

Currently, I am using KreatureMedias Layerslider and trying to make a fullwidth wave bob up and down. This is what I have at the moment... <img class="ls-layer" data-ls="durationin:1500;scalein:1.1;offsetxin:-50;loopcount:-1;loopoffsetx:0sw;loopoffset ...

Ways to expand the div to fit the width of the text after it has been wrapped

I need a continuous underline to stretch across the remaining width after the text wraps in a table cell. Here is the desired effect: https://i.sstatic.net/XNNyj.png If the text wrapping changes, the underline width should adjust accordingly. This is w ...

Resize the tab header in primefaces to fit your needs

Is there a way to change the height of the tabView's header specifically in primefaces? Take for instance the tabs with headers like "God Father I", "God Father II" on this link, I only want to adjust the height of the header and not the entire tab. ...

What is the best way to ensure Font-Face loads fonts successfully on iOS devices?

In the process of constructing a website with Gatsby.js, Styled-Components, and a custom font named 'Montserrat', I encountered an issue regarding font loading. The font appears as expected on desktop browsers during both build and hot-reloading, ...

JavaScript making a request to a web service

When trying to call a webservice in a JavaScript file using JSON, the web service is only accessible if both the .asmx file and JavaScript file are located on the local server or if they are both uploaded onto the live server. However, I am looking for a ...

CSS vertical text not functional as expected

Trying to make some text vertical, here is the CSS I'm using: h2.verticle{ color:#1a6455; border:0px solid red; writing-mode:tb-rl; filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3); -webkit-transform:rotate(90deg); -moz-transform:rota ...

What causes the disruption of vertical alignment among inline-block elements when using overflow:hidden?

Take a look at these two JSFiddles: http://jsfiddle.net/am28dsbz http://jsfiddle.net/am28dsbz/1/ Why is it that the first one shows my text aligned correctly, while the second one displays the first link lower than the second? Stack Overflow requires m ...

Scrapy and Python data gets corrupted by <br> tags causing issues

As I attempt to extract the text from Amazon reviews using scrapy, I encounter an issue. Reviews with multiple lines have their text separated by "< br >" tags within a span element. So, when I try to scrape the first review, I use this line of code: ...

The HTML button triggers a function to execute on a different webpage when clicked

I'm facing a straightforward issue that I can't seem to figure out due to my limited experience with Angular and web development. The problem revolves around two components, namely home and dashboard. In the home.component.html file, there's ...

Do you think there might be an issue with the CSS coding?

I have designed a user-friendly responsive login form that allows users to easily log in and reset their passwords. However, I am facing an issue where the username and password fields are not displaying on separate lines as intended. I have thoroughly ins ...

What is the best way to ensure that Bootstrap 4 utilizes the full width of the screen?

Currently, I have integrated Bootstrap 4 into my project with the following viewport configuration: <meta name="viewport" content="width=device-width, initial-scale=1"> While everything displays and scales properly on different devices, I noticed a ...

Can the Live Search fields be cleared?

In my current project, I am utilizing php and html files with Ajax to display the contents of a MySQL database on a webpage. The main file for displaying the contents is index.php, which retrieves data from fetch.php. I found helpful guidance on how to set ...

What is the best way to make a CSS change triggered by a onScroll() event stay in place permanently?

I need a div element to be displayed as a "scroll back to top" button on my webpage when the user has scrolled past a certain point. To achieve this, I am using the JavaScript code provided below: $(document).ready(function() { $(window).scroll(functio ...