How to align three divs containing radio inputs - html

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>

Related

How to keep checkbox from collapsing

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%;
}

Why isn't my inline working?

Below is a HTML Code but the display:inline isn't working. Am not able to understand why. But display:flex, display: -webkit-box;, display: -webkit-inline-box; , display: inline-flex; are working fine;
When i use display:inline on class position
When i use display:flex or display: -webkit-box; or display: -webkit-inline-box; or display: inline-flex; on class position
Below are the HTML Code:
<div class="form-group col-lg-12" style="padding: initial;">
<label class="control-label col-sm-12">Sample type :
</label>
<br>
<div class="col-sm-12 position">
<div style="margin-right: 15px;">
<label class="radio-inline">
<input type="radio" id="tee" name="qpd_type" value="5" checked >Type 1
</label><br/>
</div>
<div>
<label class="radio-inline">
<input type="radio" id="cia" name="qpd_type" value="2" >Type 2
</label>
</div>
</div>
</div>
Can somebody help me figure out why i cant use display:inline. Thanks.
Try this...
Remove the <br /> tag from your code.
.radio-style {
margin-right: 15px;
display: inline;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="form-group col-lg-12" style="padding: initial;">
<label class="control-label col-sm-12">Sample type :
</label>
<br>
<div class="col-sm-12 position">
<div class="radio-style">
<label class="radio-inline">
<input type="radio" id="tee" name="qpd_type" value="5" checked>Type 1
</label>
</div>
<div class="radio-style">
<label class="radio-inline">
<input type="radio" id="cia" name="qpd_type" value="2">Type 2
</label>
</div>
</div>
</div>
Also, Simply you can place the two radios into the same div. You don't need any extra css. :)
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="form-group col-lg-12" style="padding: initial;">
<label class="control-label col-sm-12">Sample type :
</label>
<br>
<div class="col-sm-12 position">
<div>
<label class="radio-inline">
<input type="radio" id="tee" name="qpd_type" value="5" checked>Type 1
</label>
<label class="radio-inline">
<input type="radio" id="cia" name="qpd_type" value="2">Type 2
</label>
</div>
</div>
</div>
Try it like this,
HTML
<div class="form-group col-lg-12" style="padding: initial;">
<label class="control-label col-sm-12">Sample type :
</label>
<br>
<div class="col-sm-12 position">
<div style="margin-right: 15px;">
<label class="radio-inline">
<input type="radio" id="tee" name="qpd_type" value="5" checked >Type 1
</label>
</div>
<div>
<label class="radio-inline">
<input type="radio" id="cia" name="qpd_type" value="2" >Type 2
</label>
</div>
</div>
</div>
CSS
.radio-inline{
float:left;
display:inline;
}

Label for Inline Radio buttons bootstrap

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

How to properly align checkbox and labels in bootstrap?

I have two rows of checkboxes and labels.Although horizontal alignment is not an issue , however there is a problem of vertical alignment of second column.How can I achieve a symmetry in this case?
<div class="form-inline">
<div class="form-group">
<div class="col-md-4">
<label class="radio-inline">
<input type="checkbox" name="inlineRadioOptionsWeek" id="Checkbox0" value="0">Sunday</label>
<label class="radio-inline">
<input type="checkbox" name="inlineRadioOptionsWeek" id="Checkbox1" value="1">Monday</label>
<label class="radio-inline">
<input type="checkbox" name="inlineRadioOptionsWeek" id="Checkbox2" value="2">Tuesday</label>
<label class="radio-inline">
<input type="checkbox" name="inlineRadioOptionsWeek" id="Checkbox3" value="3">Wednesday</label>
</div>
<div class="col-md-4">
<label class="radio-inline">
<input type="checkbox" name="inlineRadioOptionsWeek" id="Checkbox4" value="4">Thursday</label>
<label class="radio-inline">
<input type="checkbox" name="inlineRadioOptionsWeek" id="Checkbox5" value="5">Friday</label>
<label class="radio-inline">
<input type="checkbox" name="inlineRadioOptionsWeek" id="Checkbox6" value="6">Saturday</label>
</div>
</div>
JSfiddle
As you can see the alignment of Moday and Friday (checkbox and label) is not proper.
I've updated your fiddle with a fixed width on the wrapping div .col-md-4 and positioned the labels using float with the width of each label set to take 1/3 of the parents width using the calc function:
label{
float: left;
width: calc(100%/3)
}
What if you wrap each checkbox with a col-sm-3 box?
<div class="col-sm-3">
<label class="radio-inline">
<input type="checkbox" name="inlineRadioOptionsWeek" id="Checkbox3" value="3">Wednesday</label>
</div>
https://jsfiddle.net/hobs766o/1/
JsFiddle DEMO
.col-md-4.first label {
display: block;
width: 99px;
float: left;
}
.col-md-4.second label {
display: block;
width: 99px;
float: left;
}
<div class="form-inline">
<div class="form-group">
<div class="col-md-4 first">
<label class="radio-inline">
<input type="checkbox" name="inlineRadioOptionsWeek" id="Checkbox0" value="0">Sunday</label>
<label class="radio-inline">
<input type="checkbox" name="inlineRadioOptionsWeek" id="Checkbox1" value="1">Monday</label>
<label class="radio-inline">
<input type="checkbox" name="inlineRadioOptionsWeek" id="Checkbox2" value="2">Tuesday</label>
<label class="radio-inline">
<input type="checkbox" name="inlineRadioOptionsWeek" id="Checkbox3" value="3">Wednesday</label>
</div>
<div style="clear:left"></div>
<div class="col-md-4 second" style="
">
<label class="radio-inline">
<input type="checkbox" name="inlineRadioOptionsWeek" id="Checkbox4" value="4">Thursday</label>
<label class="radio-inline">
<input type="checkbox" name="inlineRadioOptionsWeek" id="Checkbox5" value="5">Friday</label>
<label class="radio-inline">
<input type="checkbox" name="inlineRadioOptionsWeek" id="Checkbox6" value="6">Saturday</label>
</div>
</div>
</div>

Align multiple inline radio button groups with labels vertically (Bootstrap 3)

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>