When it comes to organizing radio buttons and submit buttons within a form using Bootstrap, you have two main options for form layouts:
- form-horizontal
- form-inline
To achieve the desired behavior described in this scenario, the recommended form layout is form-inline
. Simply update your form's CSS class from the default value to form-inline
and adjust the display attribute of the .form-inline .radio
class accordingly.
Below is an example of how to implement this in HTML:
<form class="form-inline">
<div class="form-group">
<div class="radio">
<label>
<input type="radio" name="optionsRadios" id="optionsRadios1" value="option1" checked>
Option one is this and that - make sure to explain why it's preferred
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="optionsRadios" id="optionsRadios2" value="option2">
Option two could be something different and choosing it will deselect option one
</label>
</div>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
To style the form as needed, utilize the following CSS code:
.form-inline .radio {
display: block;
}
For a live demonstration, refer to this example.