I'm using bootstrap to create the following form. It works fine in a browser, but when I shrink it down, the boxes and labels stack on top of each other. Is there an easy fix for this in bootstrap so the labels and checkboxes stay in line even on mobile screens?
https://www.bootply.com/quVvJ0pLNo
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="form-group">
<label for="test" class="col-sm-5 control-label">mytest</label>
<div class="col-sm-7 text-center">
<div class="row">
<div class="col-sm-1">Mon</div>
<div class="col-sm-1">Tue</div>
<div class="col-sm-1">Wed</div>
<div class="col-sm-1">Thu</div>
<div class="col-sm-1">Fri</div>
<div class="col-sm-1">Sat</div>
<div class="col-sm-1">Sun</div>
</div>
<div class="row checkbox text-center">
<div class="col-sm-1 ">
<label>
<input type="checkbox" name="test" id="test2" value="1" aria-label="1">
</label>
</div>
<div class="col-sm-1">
<label>
<input type="checkbox" name="test" id="test2" value="2" aria-label="2">
</label>
</div>
<div class="col-sm-1">
<label>
<input type="checkbox" name="test" id="test2" value="3" aria-label="3">
</label>
</div>
<div class="col-sm-1">
<label>
<input type="checkbox" name="test" id="test2" value="4" aria-label="4">
</label>
</div>
<div class="col-sm-1">
<label>
<input type="checkbox" name="test" id="test2" value="5" aria-label="5">
</label>
</div>
<div class="col-sm-1">
<label>
<input type="checkbox" name="test" id="test2" value="6" aria-label="6">
</label>
</div>
<div class="col-sm-1">
<label>
<input type="checkbox" name="test" id="test2" value="7" aria-label="7">
</label>
</div>
</div>
</div>
</div>
Try using checkbox with label text and used col-xs-1 instead of col-sm-1 for same output in mobile screen.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="form-group">
<label for="test" class="col-sm-5 control-label">mytest</label>
<div class="col-sm-7 text-center">
<div class="row">
<div class="col-xs-1">
<label>
Mon<br/>
<input type="checkbox" name="test" id="test1" value="1" aria-label="1">
</label>
</div>
<div class="col-xs-1">
<label>
Tue <br/>
<input type="checkbox" name="test" id="test2" value="2" aria-label="2">
</label>
</div>
<div class="col-xs-1">
<label>
Wed <br/>
<input type="checkbox" name="test" id="test3" value="3" aria-label="3">
</label>
</div>
<div class="col-xs-1">
<label>
Thu <br/>
<input type="checkbox" name="test" id="test2" value="4" aria-label="4">
</label>
</div>
<div class="col-xs-1">
<label>
Fri <br/>
<input type="checkbox" name="test" id="test5" value="5" aria-label="5">
</label>
</div>
<div class="col-xs-1">
<label>
Sat <br/>
<input type="checkbox" name="test" id="test6" value="6" aria-label="6">
</label>
</div>
<div class="col-xs-1">
<label>
Sun <br/>
<input type="checkbox" name="test" id="test7" value="7" aria-label="7">
</label>
</div>
</div>
</div>
</div>
You can overwrite the default bootstrap css:
.form-group .row [class*="col-"] {
float: left;
width: 8.33333333%;
}
Related
I'm struggling to set my checkboxes in the below form into 3 evenly spaced columns and centered perfectly within the form. It currently looks as below...
enter image description here
But, I want it to look like...
enter image description here
HTML:
`
<form action="/signup" method="POST">
<div class="form-group">
<input
type="text"
name="firstName"
id="first-name"
class="form-control"
placeholder="First Name"
/>
</div>
<div class="form-group">
<input
type="text"
name="surname"
id="surname"
class="form-control"
placeholder="Surname"
/>
</div>
<div class="form-group">
<input
type="email"
name="email"
id="email"
class="form-control"
placeholder="Email"
/>
<small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
</div>
<fieldset class="form-group">
<legend>Pick your favourite 3 things</legend>
<div class="form-inline">
<label class="form-check-label">
<input class="form-check-input mr-2" type="checkbox" value="">
Option 1
</label>
</div>
<div class="form-inline">
<label class="form-check-label">
<input class="form-check-input mr-2" type="checkbox" value="">
Option 2
</label>
</div>
<div class="form-inline">
<label class="form-check-label">
<input class="form-check-input mr-2" type="checkbox" value="">
Option 3
</label>
</div>
<div class="form-inline">
<label class="form-check-label">
<input class="form-check-input mr-2" type="checkbox" value="">
Option 4
</label>
</div>
<div class="form-inline">
<label class="form-check-label">
<input class="form-check-input mr-2" type="checkbox" value="">
Option 5
</label>
</div>
<div class="form-inline">
<label class="form-check-label">
<input class="form-check-input mr-2" type="checkbox" value="">
Option 6
</label>
</div>
<div class="form-inline">
<label class="form-check-label">
<input class="form-check-input mr-2" type="checkbox" value="">
Option 7
</label>
</div>
<div class="form-inline">
<label class="form-check-label">
<input class="form-check-input mr-2" type="checkbox" value="">
Option 8
</label>
</div>
<div class="form-inline">
<label class="form-check-label">
<input class="form-check-input mr-2" type="checkbox" value="">
Option 9
</label>
</div>
</fieldset>
<button type="submit" class="btn btn-primary">Do it!</button>
</form>
...
<legend>Pick your 3 favourite things</legend>
<div class="row">
<div class="col-sm-4">
<div>
<label>
<input type="checkbox">
Option 1
</label>
</div>
<div>
<label>
<input type="checkbox">
Option 2
</label>
</div>
<div>
<label>
<input type="checkbox">
Option 3
</label>
</div>
</div>
<div class="col-sm-4">
<div>
<label>
<input type="checkbox">
Option 4
</label>
</div>
<div>
<label>
<input type="checkbox">
Option 5
</label>
</div>
<div>
<label>
<input type="checkbox">
Option 6
</label>
</div>
</div>
<div class="col-sm-4">
<div>
<label>
<input type="checkbox">
Option 7
</label>
</div>
<div>
<label>
<input type="checkbox">
Option 8
</label>
</div>
<div>
<label>
<input type="checkbox">
Option 9
</label>
</div>
</div>
</div>
See this JSFiddle: https://jsfiddle.net/bf4vtzry/1/
I have a form-group with inline radio buttons. The issue is that on larger screens the next text input label is appearing right below it on the right side instead of on a new line on the left side.
I have tried adding line breaks but it didn't help
Code:
<div class="container">
<form role="form">
<div class="form-group">
<div class="col-xs-6">
<label for="phone">Phone Number:</label>
<input type="text" class="form-control" id="phone" placeholder="Enter Phone Number">
</div>
<div class="col-xs-6">
<label for="optionsRadios">Preferred Contact Method</label>
<br />
<div class="radio-inline">
<input type="radio" name="optionsRadios" id="optionsRadios1" value="option1" checked>Email
</div>
<div class="radio-inline">
<input type="radio" name="optionsRadios" id="optionsRadios2" value="option2">Phone
</div>
</div>
</div>
<br />
<div class="form-group">
<div class="col-sm-12">
<label for="website">Another Text Input:</label>
<input type="url" class="form-control" id="website" placeholder="Testing">
</div>
</div>
<br/>
<button type="submit">Submit</button>
</form>
</div>
JSFiddle Demo
You can wrap every form line into row
<div class="container">
<form role="form">
<div class="row">
<div class="form-group">
<div class="col-xs-6">
<label for="phone">Phone Number:</label>
<input type="text" class="form-control" id="phone" placeholder="Enter Phone Number">
</div>
<div class="col-xs-6">
<label for="optionsRadios">Preferred Contact Method</label>
<br />
<div class="radio-inline">
<input type="radio" name="optionsRadios" id="optionsRadios1" value="option1" checked>Email
</div>
<div class="radio-inline">
<input type="radio" name="optionsRadios" id="optionsRadios2" value="option2">Phone
</div>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-sm-12">
<label for="website">Another Text Input:</label>
<input type="url" class="form-control" id="website" placeholder="Testing">
</div>
</div>
</div>
<button type="submit">Submit</button>
</form>
</div>
https://jsfiddle.net/n70kLfnc/
Change divs with class="form-group" into "row form-group"
You can try to use this CSS
.form-group .label { display: block }
But the best way is to envelope col-* always in a row div.
Here's your code rewritten:
<div class="container">
<form role="form">
<div class="row">
<div class="col-xs-6">
<div class="form-group">
<label for="phone">Phone Number:</label>
<input type="text" class="form-control" id="phone" placeholder="Enter Phone Number">
</div>
</div>
<div class="col-xs-6">
<label for="optionsRadios">Preferred Contact Method</label>
<div>
<label class="radio-inline">
<input type="radio" name="optionsRadios" id="optionsRadios1" value="option1" checked>Email
</label>
<label class="radio-inline">
<input type="radio" name="optionsRadios" id="optionsRadios2" value="option2">Phone
</label>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<label for="website">Another Text Input:</label>
<input type="url" class="form-control" id="website" placeholder="Testing">
</div>
</div>
</div>
<button type="submit">Submit</button>
</form>
</div>
here's my draft to your jsfiddle: https://jsfiddle.net/ag9aqjrz/4/
Try this
Replace <br> with <div class="clearfix"></div>
Without using <br> and clearfix you can try this format
<div class="container">
<div class="row">
<form role="form">
<div class="col-xs-6">
<div class="form-group">
<label for="phone">Phone Number:</label>
<input class="form-control" id="phone" placeholder="Enter Phone Number" type="text">
</div>
</div>
<div class="col-xs-6">
<div class="form-group">
<label for="optionsRadios">Preferred Contact Method</label>
<br>
<div class="radio-inline">
<label for="optionsRadios1">
<input name="optionsRadios" id="optionsRadios1" value="option1" checked="" type="radio">Email</label>
</div>
<div class="radio-inline">
<label for="optionsRadios2">
<input name="optionsRadios" id="optionsRadios2" value="option2" type="radio">Phone</label>
</div>
</div>
</div>
<div class="col-xs-12">
<div class="form-group">
<label for="website">Another Text Input:</label>
<input class="form-control" id="website" placeholder="Testing" type="url">
</div>
</div>
<div class="col-xs-12">
<div class="form-group">
<button type="submit">Submit</button>
</div>
</div>
</form>
</div>
</div>
<div class="container">
<form role="form">
<div class="row">
<div class="col-xs-6">
<div class="form-group">
<label for="phone">Phone Number:</label>
<input type="text" class="form-control" id="phone" placeholder="Enter Phone Number">
</div>
</div>
<div class="col-xs-6">
<div class="form-group">
<label for="optionsRadios">Preferred Contact Method</label>
<br />
<div class="radio-inline">
<input type="radio" name="optionsRadios" id="optionsRadios1" value="option1" checked>Email
</div>
<div class="radio-inline">
<input type="radio" name="optionsRadios" id="optionsRadios2" value="option2">Phone
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<div class="form-group">
<label for="website">Another Text Input:</label>
<input type="url" class="form-control" id="website" placeholder="Testing">
</div>
</div>
<div class="col-xs-12">
<button type="submit">Submit</button>
</div>
</div>
</form>
</div>
Reverse the order from
<div class="form-group">
<div class="col-sm-12">
to
<div class="col-sm-12">
<div class="form-group">
instead of use for phone number as well as Preferred Contact Method
Phone Number:
<div class="col-sm-6">
<label for="optionsRadios">Preferred Contact Method</label>
<br />
Well, the problem is with column structure, as you are mixing "col-sm-x" with "col-xs-x", you should use one of them or both, so the correct version with xs is as follows
<div class="container">
<form role="form" class="form-horizontal">
<div class="form-group">
<div class="col-xs-6">
<label for="phone">Phone Number:</label>
<input type="text" class="form-control" id="phone" placeholder="Enter Phone Number">
</div>
<div class="col-xs-6">
<label for="optionsRadios">Preferred Contact Method</label>
<br />
<div class="radio-inline">
<input type="radio" name="optionsRadios" id="optionsRadios1" value="option1" checked>Email
</div>
<div class="radio-inline">
<input type="radio" name="optionsRadios" id="optionsRadios2" value="option2">Phone
</div>
</div>
</div>
<br />
<div class="form-group">
<div class="col-xs-12">
<label for="website">Another Text Input:</label>
<input type="url" class="form-control" id="website" placeholder="Testing">
</div>
</div>
<br />
<button type="submit">Submit</button>
</form>
</div>
I was gold-plating the signup page by adding labels above each field when suddenly:
It worked fine but not with radio buttons. I'm relying on Bootstrap 3 and I think this can be solved without extra CSS but just with right nesting of Bootstrap classes. Right?
<form class="form-horizontal">
<div class="form-group">
<div class="col-sm-3">
<label for="input-password">Password:</label>
<input name="password" type="password" class="form-control" id="input-password" placeholder="Password" required="required" />
</div>
<div class="col-sm-3">
<label for="input-confirm-password">Confirm Password:</label>
<input name="confirm_password" id="input-confirm-password" type="password" class="form-control" placeholder="Confirm Password" required="required" />
</div>
</div>
<div class="form-group">
<div class="col-sm-6">
<label for="input-address">Address:</label>
<input name="address" id="input-address" type="text" class="form-control" placeholder="Address" />
</div>
</div>
<label class="row">Gender:</label>
<div class="form-group">
<div class="col-sm-3">
<label class="radio-inline">
<input name="gender" id="input-gender-male" value="Male" type="radio" />Male
</label>
</div>
<div class="col-sm-3">
<label class="radio-inline">
<input name="gender" id="input-gender-female" value="Female" type="radio" />Female
</label>
</div>
</div>
<div class="form-group">
<label>Account Type:</label>
<div class="col-sm-3">
<label class="radio-inline">
<input name="account_type" id="input-type-student" value="Student" type="radio" />Student
</label>
</div>
<div class="col-sm-3">
<label class="radio-inline">
<input name="account_type" id="input-type-tutor" value="Tutor" type="radio" />Tutor
</label>
</div>
</div>
</form>
I tried 2 different placement of the elements to resolve this issue as you can see but it didn't work.
I even tried putting a div around each set of the radio buttons and then gave a label for it but that didn't work either.
You can do it this way:
<div class="form-group">
<div class="col-sm-6">
<label for="input-type">Account Type *:</label>
<div id="input-type" class="row">
<div class="col-sm-6">
<label class="radio-inline">
<input name="account_type" id="input-type-student" value="Student" type="radio" />Student
</label>
</div>
<div class="col-sm-6">
<label class="radio-inline">
<input name="account_type" id="input-type-tutor" value="Tutor" type="radio" />Tutor
</label>
</div>
</div
</div>
</div>
Do the same for the other radio buttons group.
Explanation: The col-sm-6 of the outer div is now 100% and can be divided 50:50 by col-sm-6 and col-sm-6
I have the following HTML:
<div class="col-sm-6" style="border: 1px solid #ddd; border-radius: 15px;">
<div style="margin: 8px 0 8px 5px;">
<h3>Constitutional</h3>
<div class="row">
<div class="col-sm-6">
<label class="radio-inline">Group 1.1:</label>
<div class="radio radio-info radio-inline">
<input id="ros-wch-na" type="radio" name="ros-wch" value="na" checked />
<label for="ros-wch-na">N/A</label>
</div>
<div class="radio radio-info radio-inline">
<input id="ros-wch-y" type="radio" name="ros-wch" value="y" />
<label for="ros-wch-y">Yes</label>
</div>
<div class="radio radio-info radio-inline">
<input id="ros-wch-n" type="radio" name="ros-wch" value="n" />
<label for="ros-wch-n">No</label>
</div>
</div>
<div class="col-sm-6">
<label class="radio-inline">Group 1.2:</label>
<div class="radio radio-info radio-inline">
<input id="ros-an-na" type="radio" name="ros-an" value="na" checked />
<label for="ros-an-na">N/A</label>
</div>
<div class="radio radio-info radio-inline">
<input id="ros-an-y" type="radio" name="ros-an" value="y" />
<label for="ros-an-y">Yes</label>
</div>
<div class="radio radio-info radio-inline">
<input id="ros-an-n" type="radio" name="ros-an" value="n" />
<label for="ros-an-n">No</label>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<label class="radio-inline">Row2 Group1:</label>
<div class="radio radio-info radio-inline">
<input id="ros-ns-na" type="radio" name="ros-ns" value="na" checked />
<label for="ros-ns-na">N/A</label>
</div>
<div class="radio radio-info radio-inline">
<input id="ros-ns-y" type="radio" name="ros-ns" value="y" />
<label for="ros-ns-y">Yes</label>
</div>
<div class="radio radio-info radio-inline">
<input id="ros-ns-n" type="radio" name="ros-ns" value="n" />
<label for="ros-ns-n">No</label>
</div>
</div>
<div class="col-sm-6">
<label class="radio-inline">Row2 Group2:</label>
<div class="radio radio-info radio-inline">
<input id="ros-hc-na" type="radio" name="ros-hc" value="na" checked />
<label for="ros-hc-na">N/A</label>
</div>
<div class="radio radio-info radio-inline">
<input id="ros-hc-an" type="radio" name="ros-hc" value="y" />
<label for="ros-hc-an">Yes</label>
</div>
<div class="radio radio-info radio-inline">
<input id="ros-hc-an" type="radio" name="ros-hc" value="n" />
<label for="ros-hc-n">No</label>
</div>
</div>
</div>
</div>
</div>
I'm using awesome-bootstrap-checkbox for the radio buttons, so that's why the markup is a bit different and what the radio-* classes are for.
The goal here is to have them all line up vertically and horizontally. Horizontally is not a problem, that works fine. However, labels of different lengths cause the radio button groups to shift, and it becomes uneven, as shown here. The desired effect is to have the radio groups align vertically and look even.
What would the proper CSS/HTML be so that the groups align both horizontally and vertically, no matter the label?
Divide the Label part and Radio-boxes part into two. Have labels with fixed width and wrap the long labels.
<div class="col-sm-6">
<div class='labelsDiv'>
<label class="radio-inline">Group 1.2:</label>
</div>
<div class='radiosDiv'>
<div class="radio radio-info radio-inline">
<input id="ros-an-na" type="radio" name="ros-an" value="na" checked />
<label for="ros-an-na">N/A</label>
</div>
<div class="radio radio-info radio-inline">
<input id="ros-an-y" type="radio" name="ros-an" value="y" />
<label for="ros-an-y">Yes</label>
</div>
<div class="radio radio-info radio-inline">
<input id="ros-an-n" type="radio" name="ros-an" value="n" />
<label for="ros-an-n">No</label>
</div>
</div>
</div>
Wide space between label for vertical radio button and first choice. In an ideal world, I would love it to be the same amount of space as between the field labels and the top line on the fields. Any thoughts or ideas? Thanks in advance.
http://jsfiddle.net/steveadams617/MgcDU/8543/
<div class="container">
<form>
<div class="row">
<div class="col-sm-6">
<div class='form-group'>
<label for="provider_id">Provider</label>
<div>
<input class="form-control" type="text" maxlength="255" value="" name="provider_id_auto" id="provider_id_auto"/>
</div>
</div>
</div>
<div class="col-sm-3">
<div class='form-group'>
<label for='phone_us'>Phone</label>
<input class='form-control phone_us' type='text' maxlength='14' value='' name='phone_us' id='phone_us'/>
</div>
</div>
</div><!-- .row -->
<div class='row'>
<div class="col-sm-6">
<label for="med_coverage_id">Insurance Coverage</label>
<div class="radio">
<label>
<input type="radio" name="med_coverage_id" value="1" checked />
Pending
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="med_coverage_id" value="2" />
Covered
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="med_coverage_id" value="3" />
Needs Prior Approval
</label>
</div>
</div>
</div><!-- .row -->
</form>
</div><!-- .container -->
Your div .radio has a margin-top of 10px. You can manually adjust this like so
<div class="radio" style="margin-top: 0px;">
<label>
<input type="radio" name="med_coverage_id" value="1" checked="">Pending </label>
</div>
or of course edit the stylesheet or add your own style to the .radio-class (eg if you are using a CDN).