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>
Related
I have three divs in a form that accept radio buttons as input. Currently with my css it looks like this:
Please see this link
O Text O Text O Text
O Text O Text&Text O Text
O Text O Text
How can I edit my css to make it so that the radio buttons are vertically aligned AND the whole set of radio inputs center aligned , something like this:
O Text O Text O Text
O Text O Text&Text O Text
O Text O Text
This is the code I have
Thank you!
<div class="form-group">
<label for="material" class="text-light">Text</label>
<div class="radio inline">
<input type="radio" id="plastic" name="material" value="Plastic">
<label for="plastic" class="radio-label">Text</label>
</div>
<div class="radio inline">
<input type="radio" id="cans" name="material" value="Cans">
<label for="cans" class="radio-label">Text</label>
</div>
<div class="radio inline">
<input type="radio" id="paper" name="material" value="Paper">
<label for="paper" class="radio-label">Text</label>
</div>
</div>
<div class="form-group">
<label for="relationship" class="text-light">Text</label>
<div class="radio inline">
<input type="radio" id="school" name="relationship" value="School">
<label for="school" class="radio-label">Text</label>
</div>
<div class="radio inline">
<input type="radio" id="family" name="relationship" value="Friends & Family">
<label for="family" class="radio-label">TextText</label>
</div>
<div class="radio inline">
<input type="radio" id="company" name="relationship" value="Company">
<label for="company" class="radio-label">Company</label>
</div>
</div>
<div class="form-group">
<label for="frequency" class="text-light">Type</label>
<div class="radio inline">
<input type="radio" class="freq" name="frequency" id="Repeating" value="Repeating">
<label for="Repeating" class="radio-label">Text</label>
</div>
<div class="radio inline">
<input type="radio" class="freq" name="frequency" id="One-Time" value="One-Time">
<label for="One-Time" class="radio-label">Text</label>
</div>
If you wrap these form-groups in a container, you can set that container to display: flex which will allow you to use flexbox properties to align your form groups as needed.
<div class="radio-container">
<fieldset class="form-group">
<legend id="material" class="text-light">Text</legend>
<div class="radio inline">
<input type="radio" id="plastic" name="material" value="Plastic">
<label for="plastic" class="radio-label">Text</label>
</div>
<div class="radio inline">
<input type="radio" id="cans" name="material" value="Cans">
<label for="cans" class="radio-label">Text</label>
</div>
<div class="radio inline">
<input type="radio" id="paper" name="material" value="Paper">
<label for="paper" class="radio-label">Text</label>
</div>
</fieldset>
<fieldset class="form-group">
<legend id="relationship" class="text-light">Text</legend>
<div class="radio inline">
<input type="radio" id="school" name="relationship" value="School">
<label for="school" class="radio-label">Text</label>
</div>
<div class="radio inline">
<input type="radio" id="family" name="relationship" value="Friends & Family">
<label for="family" class="radio-label">TextText</label>
</div>
<div class="radio inline">
<input type="radio" id="company" name="relationship" value="Company">
<label for="company" class="radio-label">Company</label>
</div>
</fieldset>
<fieldset class="form-group">
<legend id="frequency" class="text-light">Type</legend>
<div class="radio inline">
<input type="radio" class="freq" name="frequency" id="Repeating" value="Repeating">
<label for="Repeating" class="radio-label">Text</label>
</div>
<div class="radio inline">
<input type="radio" class="freq" name="frequency" id="One-Time" value="One-Time">
<label for="One-Time" class="radio-label">Text</label>
</div>
</fieldset>
</div>
.radio-container{
display: flex;
justify-content: center;
}
You can use display:flex along with a width:Xpx to create aligned rows. Then justify-content: center; on the whole flex container to center it. If you want the title label text to align with the radio label text you can set the radios to absolute postion and put a common padding on all labels
.container {
display: flex;
margin: auto;
justify-content: center;
}
.radio.inline {
width: 100px;
}
label {
padding-left: 25px;
}
input[type='radio'] {
position: absolute;
}
<div class="container">
<div class="form-group">
<label for="material" class="text-light">Text</label>
<div class="radio inline">
<input type="radio" id="plastic" name="material" value="Plastic">
<label for="plastic" class="radio-label">Text</label>
</div>
<div class="radio inline">
<input type="radio" id="cans" name="material" value="Cans">
<label for="cans" class="radio-label">Text</label>
</div>
<div class="radio inline">
<input type="radio" id="paper" name="material" value="Paper">
<label for="paper" class="radio-label">Text</label>
</div>
</div>
<div class="form-group">
<label for="relationship" class="text-light">Text</label>
<div class="radio inline">
<input type="radio" id="school" name="relationship" value="School">
<label for="school" class="radio-label">Text</label>
</div>
<div class="radio inline">
<input type="radio" id="family" name="relationship" value="Friends & Family">
<label for="family" class="radio-label">TextText</label>
</div>
<div class="radio inline">
<input type="radio" id="company" name="relationship" value="Company">
<label for="company" class="radio-label">Company</label>
</div>
</div>
<div class="form-group">
<label for="frequency" class="text-light">Type</label>
<div class="radio inline">
<input type="radio" class="freq" name="frequency" id="Repeating" value="Repeating">
<label for="Repeating" class="radio-label">Text</label>
</div>
<div class="radio inline">
<input type="radio" class="freq" name="frequency" id="One-Time" value="One-Time">
<label for="One-Time" class="radio-label">Text</label>
</div>
</div>
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%;
}
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 want to set up checkboxes side-by-side to visually represent something. It looks fine on my site but falls apart when trying to resize or on an iPad. I'm probably making a silly mistake but I would appreciate any corrections to my code.
http://www.bootply.com/1a5yzjMAGp
<div class="col-md-6">
<div class="col md-6">
<div class="checkbox checkbox-primary">
<input id="checkbox1" type="checkbox" disabled="disabled" />
<label for="checkbox1">
Art
</label>
</div>
<div class="checkbox checkbox-success">
<input id="checkbox1" type="checkbox" disabled="disabled" checked="checked" />
<label for="checkbox2">
Drama
</label>
</div>
<div class="checkbox checkbox-success">
<input id="checkbox1" type="checkbox" disabled="disabled" checked="checked" />
<label for="checkbox3">
Foods and Nutrition
</label>
</div>
<div class="checkbox checkbox-success">
<input id="checkbox1" type="checkbox" disabled="disabled" checked="checked" />
<label for="checkbox4">
Geography
</label>
</div>
<div class="checkbox checkbox-success">
<input id="checkbox1" type="checkbox" disabled="disabled" checked="checked" />
<label for="checkbox5">
Industrial Arts/Shop Programs
</label>
</div>
</div>
</div>
<div class="col md-6">
<div class="checkbox checkbox-success">
<input id="checkbox1" type="checkbox" disabled="disabled" />
<label for="checkbox6">
Math
</label>
</div>
<div class="checkbox checkbox-success">
<input id="checkbox1" type="checkbox" disabled="disabled" />
<label for="checkbox6">
Music
</label>
</div>
<div class="checkbox checkbox-success">
<input id="checkbox1" type="checkbox" disabled="disabled" checked="checked" />
<label for="checkbox6">
Technology
</label>
</div>
<div class="checkbox checkbox-success">
<input id="checkbox1" type="checkbox" disabled="disabled" />
<label for="checkbox6">
Science
</label>
</div>
<div class="checkbox checkbox-success">
<input id="checkbox1" type="checkbox" disabled="disabled" />
<label for="checkbox6">
Physical Education/Health
</label>
</div>
</div>
You can try giving the div with class checkbox the following properties:
.checkbox {
width:250px;
float:left;
}
You can play around with width to make it fit to you needs.
Here's the fiddle: JSBIN