Reputation: 10280
This has wasted several hours of my day. Here's a very simple form, with 2 radio buttons and a label, on bootply. This works as expected on 2.3.2: 'Date Range' on the left, buttons on the right. On Bootstrap 3, everything's out, it's basically vertical instead of horizontal, the text is bold, and it's just a mess. Any ideas, short of re-doing this as a grid?
Thanks.
EDIT
This is the expected layout, when B2.3.2 is selected on bootply:
This is what I get when I select any B3+:
Upvotes: 19
Views: 79257
Reputation: 526
I needed the same arrangement but with both horizontal and vertical radios. For Bootstrap 3.2, there is a form-horizontal that works nicely with columns.
<form class="form-horizontal" role="form">
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<p class="bg-warning">Note: In the Stack Snippet, you may need to click "Full Page", otherwise the container is narrow enough to cause Bootstrap to stack the labels over the fields.</p>
<form class="form-horizontal" role="form">
<div class="form-group">
<label class="col-sm-4 control-label">Season</label>
<div class="col-sm-8">
<label class="radio-inline"> <input type="radio" name="season" id="seasonSummer" value="summer" checked> Summer </label>
<label class="radio-inline"> <input type="radio" name="season" id="seasonWinter" value="winter"> Winter </label>
<label class="radio-inline"> <input type="radio" name="season" id="seasonSpringFall" value="spring-fall" disabled> Spring-Fall </label>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">Clouds</label>
<div class="col-sm-8">
<label class="radio-inline"> <input type="radio" name="clouds" id="Clear" value="clear" checked> Clear </label>
<label class="radio-inline"> <input type="radio" name="clouds" id="Cloudy" value="cloudy"> Cloudy </label>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">Load Forecast</label>
<div class="col-sm-8">
<div class="radio">
<label> <input type="radio" name="load" id="WeekdayAverage" value="weekdayaverage" checked> Weekday - Average </label>
</div>
<div class="radio">
<label> <input type="radio" name="load" id="WeekdayPeak" value="weekdaypeak"> Weekday - Peak </label>
</div>
<div class="radio">
<label> <input type="radio" name="load" id="Weekend" value="weekend" disabled> Weekend </label>
</div>
</div>
</div>
</form>
</div>
Upvotes: 37
Reputation: 34652
To do what you want to do, you do have to use col-* classes as all form elements are 100% width, so you have to have a col-* to fix the width you want. You can use col-xs-* and it will be for all sizes, not responsive:
EXAMPLE: http://bootply.com/102912
<form class="form-horizontal">
<fieldset>
<div class="form-group">
<label class="col-xs-3 control-label">Date Range</label>
<div class="col-xs-9">
<div class="radio">
<label>
<input id="inlineradio1" name="sampleinlineradio" value="option1" type="radio">
Radio 0</label>
</div>
<div class="radio">
<label>
<input id="inlineradio1" name="sampleinlineradio" value="option1" type="radio">
Radio 0</label>
</div>
<div class="radio">
<label>
<input id="inlineradio1" name="sampleinlineradio" value="option1" type="radio">
Radio 0</label>
</div>
</div>
</div>
</fieldset>
</form>
If you want radios, checkboxes, or other form elements on the same line without the use of column classes, the class for the form is .form-inline
:
<form class="form-inline">
<div class="form-group">
<label class="radio-inline">Date Range</label>
<label class="radio-inline">
<input id="inlineradio1" name="sampleinlineradio" value="option1" type="radio">
Radio 0</label>
<label class="radio-inline">
<input id="inlineradio2" name="sampleinlineradio" value="option2" type="radio">
Radio 2</label>
<label class="radio-inline">
<input id="inlineradio3" name="sampleinlineradio" value="option3" type="radio">
Radio 3</label>
</div>
<!--form-group-->
</form>
Upvotes: 27