Any solutions for dealing with longer labels in Bootstrap form-floating?

Is there a way to use Bootstrap's form-floating feature with longer labels so that the text box automatically expands to accommodate the text but doesn't cut off on white-space wrap when too long? I'd like to avoid using position-relative to pop it out of flow, as this should be a last resort if form-floating doesn't meet our requirements.

You can see the issue in action on mobile screens or smaller columns in this jsFiddle: https://jsfiddle.net/tzqr36ja/3/.

Below is the current implementation based on Bootstrap's form-floating:

.cms-forms-container .col-sm-6 {
  position: relative;
  min-height: 1px;
  padding-right: 15px;
  padding-left: 15px
}

.cms-form-fieldset {
  padding: 0;
  background-color: inherit;
}

.cms-form-fieldset .cms-forms-field {
  margin: 0;
  padding-top: 7px;
}

.cms-forms-fieldset .cms-forms-field input,
.cms-forms-fieldset .cms-forms-field textarea,
.cms-forms-fieldset .cms-forms-field select {
  max-width: none !important;
  width: 100%;
  border-radius: 5px;
  background: #ffffff;
  color: #666666;
  position: relative;
  -webkit-appearance: none;
  margin: 0;
}

.cms-forms-fieldset .cms-forms-field select {
  -webkit-appearance: menulist;
  padding-right: 5px;
}

.cms-forms-field div label {
  vertical-align: bottom;
  display: inline-block !important;
}

.form-floating>.form-control {
  height: unset;
}

.form-floating>label {
  white-space: normal;
}
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="31535e5e45424543504171041f011f03">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="13717c7c67606761726353263d233d21">[email protected]</a>/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>

<div class="fieldset cms-form-fieldset">
  <div class="row">
    <div class="cms-forms-container col-12 col-sm-6">
      <div class="cms-forms-field custom-label-a">
        <div class="cms-forms-field-wrapper form-floating mb-2">
          <select class="form-control valid input validation-valid" name="custom-field-a" id="#">
            <option>n/a</option>
            <option value="Bacon">Bacon</option>
            <option value="Pork belly">Pork belly</option>
          </select>
          <label for="custom-field-a" class="cms-forms-label">
             Bacon ipsum dolor amet andouille capicola pork chop fatback filet mignon buffalo burgdoggen. 
          </label>
        </div>
      </div>
    </div>
  </div>
</div>

Answer №1

Depending on the desired look, you can set a height value for your <select. Consider adjusting the height and/or width to achieve the desired appearance.

.custom-select-me select {
  height: 5em !important;
}

.custom-select-me-wider select {
  height: 5em !important;
}

.custom-select-me-wider label {
  width: 22em !important;
}
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="abc9c4c4dfd8dfd9cadbeb9e859b">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b9dbd6d6cdcacdcbd8c9f98c9789978b">[email protected]</a>/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>

<div class="fieldset cms-form-fieldset">
  <div class="row">
    <div class="cms-forms-container col-12 col-sm-6">
      <div class="custom-select-me cms-forms-field custom-label-a">
        <div class=" cms-forms-field-wrapper form-floating mb-2 ">
          <select class="form-control valid input validation-valid form-select" name="custom-field-a">
            <option>n/a</option>
            <option value="Bacon">Bacon</option>
            <option value="Pork belly">Pork belly</option>
          </select>
          <label for="custom-field-a" class="custom-select-me cms-forms-label">Bacon ipsum dolor amet andouille capicola pork chop fatback filet mignon buffalo burgdoggen.</label>
        </div>
      </div>
    </div>
  </div>
  <div class="row">
    <div class="cms-forms-container col-12 col-sm-6">
      <div class="custom-select-me-wider cms-forms-field custom-label-a">
        <div class=" cms-forms-field-wrapper form-floating mb-2 ">
          <select class="form-control valid input validation-valid form-select" name="custom-field-a">
            <option>n/a</option>
            <option value="Bacon">Bacon</option>
            <option value="Pork belly">Pork belly</option>
          </select>
          <label for="custom-field-a" class="custom-select-me cms-forms-label">Bacon ipsum dolor amet andouille capicola pork chop fatback filet mignon buffalo burgdoggen.</label>
        </div>
      </div>
    </div>
  </div>
</div>

Trying something different here

.custom-select-me-wider>.cms-forms-field-wrapper {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
}

.custom-select-me-wider select.custom-select-me {
  grid-column: 1;
  grid-row: 1;
  border: 1px solid blue;
  z-index: 2;
  background-color: transparent;
}

.custom-select-me-wider label.custom-select-me {
  grid-column: 1;
  grid-row: 1;
  opacity: .65;
  transform: scale(.85) translateY(-0.5rem) translateX(0.15rem);
  border: solid 1px red;
  z-index: 1;
}
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5e3c31312a2d2a2c3f2e1e6b706e706c">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6e0c01011a1d1a1c0f1e2e5b405e405c">[email protected]</a>/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>

<div class="fieldset cms-form-fieldset">
  <div class="row mb-3 pb-3">
    <div class="cms-forms-container col-12 col-sm-6">
      <div class=" cms-forms-field custom-label-a">
        <div class="cms-forms-field-wrapper form-floating mb-2 ">
          <select class="form-control valid input validation-valid form-select" name="custom-field-a">
            <option>n/a</option>
            <option value="Bacon">Bacon</option>
            <option value="Pork belly">Pork belly</option>
          </select>
          <label for="custom-field-a" class="custom-select-me cms-forms-label">Bacon ipsum dolor amet andouille capicola pork chop fatback filet mignon buffalo burgdoggen.NOT this one!</label>
        </div>
      </div>
    </div>
  </div>
  <div class="row">
    <div class="cms-forms-container col-12 col-sm-6">
      <div class="custom-select-me-wider cms-forms-field custom-label-a">
        <div class="cms-forms-field-wrapper mb-2">
          <select class="custom-select-me form-control form-select valid input validation-valid " name="custom-field-a">
            <option>n/a</option>
            <option value="Bacon">Bacon</option>
            <option value="Pork belly">Pork belly</option>
          </select>
          <label for="custom-field-a" class="custom-select-me cms-forms-label">Bacon ipsum dolor amet andouille capicola pork chop fatback filet mignon buffalo burgdoggen. tester out with huge amount of text here 
          </label>
        </div>
      </div>
    </div>
  </div>
</div>

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

Angular 5 mobile row aligns vertically, not inline with Bootstrap

Is there a way to make the row inline when the width is less than 579px? I want it to look the same on both mobile and desktop. "styles": [ "../node_modules/font-awesome/scss/font-awesome.scss", "../node_modules/angular-bootstrap-md/scss/bootstra ...

Differences in behavior of multiple select with track by in Angular versions above 1.4.x

I recently upgraded my product from Angular 1.2.x to 1.4.x. Since updating to angularjs 1.4.x, I've encountered an issue: What I have: I included code snippets for both angular 1.2.0 and 1.4.8. You can check out the comparison on JSFIDDLE. Explanat ...

Content not being displayed by Javascript

I'm having trouble displaying content using JavaScript DOM. Every time I try to run my code, the page comes up blank. Here is an example of my HTML file: <!DOCTYPE html> <html> <head> <title>Radiant HQ</titl ...

Exploring Laravel 4's CSS Routing

Attempting to connect my CSS document in Laravel 4 has been a bit challenging. The location of my CSS file is: public/css/style.css In the view, I have the following link: <link type="text/css" rel="stylesheet" href="{{URL::asset('css/style.css ...

Why is it that this particular line of code sometimes gives me an "undefined" result before returning an actual value?

Why does the method 'equal' always return with an "undefined" followed by a number? And when I try to parse it, it returns me a NaN. <!DOCTYPE> <html> <head> <script> var fnum = 0; var secondNum; var operation; functi ...

How can nunjucks templates be accessed from NPM (node modules)?

Is there a solution to make nunjucks imports/includes resolve from the NPM node_modules directory? Let's say we have installed a package as follows: npm i -S @example/cards Now, we need to import from it in a template like this: {% import "@exampl ...

What is the process for including a JavaScript file in an HTML document?

Greetings to all and thank you for taking the time! I have a straightforward query for you.. I have designed an html page featuring only a basemap (open street map). Moreover, I possess a javascript file which utilizes your coordinates to calculate a perce ...

trouble with the layout of the table

Could you assist me in improving the design to enhance data clarity? Your help would be greatly appreciated. Thank you for your anticipated response. CSS File: table-layout: fixed; width: 100%; border-collapse: collapse; table-layout: fixed; ove ...

Step-by-step guide: Crafting an UP Arrow solely with HTML and CSS

What is the method to utilize solely HTML and CSS for creating a triangle? I am in need of constructing a thick triangle, but want to achieve this using only CSS So far, I have experimented with the following code: .arrow-up { width: 0; height: 0 ...

The <select> list appears wider on Windows compared to Mac

Is there a way to achieve consistent width for a wide select list on different operating systems and browsers? I've noticed that the width of the select box varies between Windows and Mac OS when viewed in Chrome or other browsers. For example, if yo ...

Which is the ideal library for creating this specific chart - shown in the image in the description - in reactjs?

After numerous unsuccessful attempts, I have finally decided to seek help in creating this chart. I would highly appreciate any assistance that can be provided. https://i.sstatic.net/jtQ3I.jpg ...

Clicking on a button within the parent element will enable you to remove the parent element multiple times with the use of VanillaJS

Within a ul element, each li contains multiple elements in the following structure: <ul> <li> <div> <p>some text </p> <button>delete</button> <div> </li> <li> ...

Dynamic Sizing of Inline Input Fields in Bootstrap 3 Using Narrow Columns

My goal is to create an inline form within a small container (.col-sm-4) without it wrapping into multiple lines. I want the inputs to adjust to the column size while also having the button in the desired position. To achieve this, I have managed to remove ...

The Server-Sent Event feature seems to be malfunctioning as it appears that browsers are unable to detect any events sent through Server-Sent

I have successfully implemented server-sent events (HTML5) in my project without using node.js. It is a simple webpage (another JSP page) that makes a call and receives a response. However, when I receive the response, none of the methods/functions (onopen ...

Approach to decoupling design elements from DOM interactions

Seeking recommendations or guidelines for effectively segregating classes utilized for browser styling and DOM manipulation. Specifically, we are developing a single-page app using backbone.js and heavily relying on jQuery for dynamically updating page el ...

Adjust the size of an element by utilizing a different element

I'm facing a challenge with this code. I need to dynamically set the width of the "wrap-description" divs to be equal to the width of the corresponding "picture-damage" images plus an additional 20 pixels. Since there will be multiple elements for bot ...

"Encountering issue with SCSS variable not being applied to background in file

$enable-grid-classes: false; $enable-cssgrid:true; $deepBlue: #032f3e; body { --bs-body-bg: orange ; } @import "https://fonts.googleapis.com/css2?family=Space+Grotesk:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="463121 ...

Deletion of a custom function in JavaScript

I have written some basic code to generate and remove an image using functions. Specifically, I need help with removing the image created by the function Generate() when a button linked to the function Reset1() is clicked. Here's the code snippet for ...

Learning to use Material-UI: Wrapping a list into columns

Currently, I am using Material-UI to display a list of checkboxes, similar to the example shown here. The problem arises when my list contains around 30 items and I am placing them inside a dialog box. I want the checkbox list items to stack vertically up ...

Transfer the textbox value from page-1 to page-2 seamlessly with the help of AngularJS UI-routing

I'm attempting to transfer the textbox value from Page-1 to Page-2 using the code below, but I am encountering difficulties. Page-1.html <div > <div style="height: 400px"> <h2>Partial view-1</h2> <p> ...