3

I would like my form labels to be left-aligned to the input fields, which I have achieved with this HTML:

<fieldset>
    <div class="form-group row">
        <label class="col-auto col-form-label-sm">Name</label>
        <div class="col">
            <input type="text" class="form-control form-control-sm" required />
        </div>
    </div>
    <div class="form-group row">
        <label class="col-auto col-form-label-sm">Really Really Long Name</label>
        <div class="col">
            <input type="text" class="form-control form-control-sm" required />
        </div>
    </div>
</fieldset>

I used col-auto with my labels because I wanted the labels to fit and to never be line-wrapped and for the input field to get the remainder of the horizontal space. The only issue is I didn't realize that col-auto is only calculated per that row, so I end up with label columns of varying widths!

Is there a way to make all label columns auto size to fit the widest label but to all be that same width? It's especially important that this is an automatic resizing because we support multiple languages and won't know a hard-coded width ahead of time of each possible label text.

EDIT:

Here's what it looks like when I use col-auto

enter image description here

The red lines mark where the individual label column widths end up when using col-auto. The green line represents how I want all the columns to be sized, I want them all to be the width of the widest label column, which in this case is the one for "Instructions URL:"

Kyle V.
  • 4,452
  • 8
  • 42
  • 72

1 Answers1

3

have you tried setting a width and using .text-nowrap? I recently had a similar issue and this worked for me.

https://getbootstrap.com/docs/4.0/utilities/text/