min-width for column in Bootstrap grid system

sasha_trn picture sasha_trn · Feb 3, 2016 · Viewed 61.1k times · Source

I have following HTML with Bootstrap CSS.

<div class="row">
  <div class="col-sm-4" style="min-width: 66px;">Name</div>
  <div class="col-sm-1" style="min-width: 120px;">Instance name</div>
  <div class="col-sm-7" style="min-width: 87px;">Due date</div>
</div>

Without 'min-width' a width of the second column in some cases is less than 120px and 'Instance name' isn't fully visible. So that I've added 'min-width' and width of row becomes more than 100% in that cases. The last column is wrapped into new line.

I want to have bootstrap dynamic column width and that Instance name doesn't disappeared when I reduce browser window size. How can I achieve such behavior?

Answer

Chris picture Chris · Feb 3, 2016

Not sure if there is such a way to accomplish what you want.

The col-sm-x defines specific width percentages of your viewport, and if you provide custom values, then the accumulated width of all columns will either be more or less than 100%, which is not the desired behaviour.

Instead, you can provide multiple classes for the same div. Example:

<div class="row">
  <div class="col-sm-4 col-xs-1">Name</div>
  <div class="col-sm-1 col-xs-3">Instance name</div>
  <div class="col-sm-7 col-xs-2">Due date</div>
</div>

If this is solution does not suffice, then you will most likely come up with a javascript solution of some sort that manually sets the width of the other divs.

There seems to be another, similar question previously posted here on stackoverflow. Have a look here.

Bootstrap Grid on W3Schools