With Twitter Bootstrap 3.3.7, I am trying to line up multiple questions that have inline radio button answers and have the radio buttons for all questions line up to be displayed nicer for end users.
If this is on a Extra small device, I want the radio buttons to be on the next line.
The trouble I am having is that applying col-sm-6 (or any column size) seems to not work as I expect. The help-block doesn't fully go to the next line, it's stuck under the radio buttons.
I'm looking to be able to use proper Twitter Bootstrap form syntax. Is this possible with the form syntax, or does this require doing it with their own rows/cols?
An example of a question: JSFiddle https://jsfiddle.net/y8j5f0of/
<div class="row">
<div class="form-group">
<label class="col-sm-6">This is an example question</label>
<div class="col-sm-6">
<label class="radio-inline">
<input type="radio" name="answer1" value="Yes"> Yes
</label>
<label class="radio-inline">
<input type="radio" name="answer1" value="No"> No
</label>
</div>
<span class="help-block">This is an example help block that has a lot of text that should start under the question instead of the answer.</span>
</div>
</div>
Answers are lined up, but the output isn't flowing properly.
If I remove the col-sm-6, everything flows as expected but the answers aren't lined up. Also, this doesn't allow the radio buttons to go to their own line for Extra small device.
JSFiddle https://jsfiddle.net/nz36k74o/1/
<div class="row">
<div class="form-group">
<label>This is an example question 1 that is longer than question 2</label>
<label class="radio-inline">
<input type="radio" name="answer1" value="Yes"> Yes
</label>
<label class="radio-inline">
<input type="radio" name="answer1" value="No"> No
</label>
<span class="help-block">This is an example help block that has a lot of text that should start under the question instead of the answer.</span>
</div>
</div>
Output
The help block should really be in a new row. If it is supposed to be underneath the other content, then its not part of the row. That's the basis of the Bootstrap grid system. A basic question block should look like this:
<div class="form-group">
<div class="row">
<label class="col-sm-6">This is an example question 1 that is longer than question 2</label>
<div class="col-sm-6">
<label class="radio-inline">
<input type="radio" name="answer1" value="Yes"> Yes
</label>
<label class="radio-inline">
<input type="radio" name="answer1" value="No"> No
</label>
</div>
</div>
<div class="row">
<div class="col-md-12">
<span class="help-block">This is an example help block that has a lot of text that should start under the question instead of the answer.</span>
</div>
</div>
</div>
Check out the fiddle (sorry onlyhad time to do one)
Here is one solution to align the question correctly. It adds in some extra html tags but I believe it solves your issue.
This is the updated fiddle.
https://jsfiddle.net/nz36k74o/3/
<div class="form-group">
<label class="col-sm-6">This is an example question</label>
<div class="col-sm-6">
<label class="radio-inline">
<input type="radio" name="answer1" value="Yes"> Yes
</label>
<label class="radio-inline">
<input type="radio" name="answer1" value="No"> No
</label>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<span class="help-block">This is an example help block.</span>
</div>
</div>
Related
I have a couple of checkbox that I would like to make only one of them clickable. I have tried different solutions on stack overflow. I also changes changed the input type to radio and I have used the following code but still its not working:
$(document).ready(function () {
$('input[type=radio]').change(function() {
// When any radio button on the page is selected,
// then deselect all other radio buttons.
$('input[type=radio]:checked').not(this).prop('checked', false);
});
});
My Code is as follows:
<div id="options-content5" class="collapse">
<div class="checkbox checkbox-theme checkbox-circle">
<input id="checkbox15" type="checkbox" name="last24">
<label for="checkbox15">
Last 24 Hours
</label>
</div>
<div class="checkbox checkbox-theme checkbox-circle">
<input id="checkbox16" type="checkbox" name="last3Days">
<label for="checkbox16">
Last 3 days
</label>
</div>
<div class="checkbox checkbox-theme checkbox-circle">
<input id="checkbox17" type="checkbox" name="last7Days">
<label for="checkbox17">
Last 7 days
</label>
</div>
<br>
</div>
If you want to make only one of a set of checkboxes clickable, use radio buttons with the same name. This will be much better for usability and accessibility. Here's an article from the Nielsen Norman Group about how to choose between checkboxes and radio buttons and why it matters. https://www.nngroup.com/articles/checkboxes-vs-radio-buttons/
I'd recommend using the values in place of your names to differentiate.
<div id="options-content5" class="collapse">
<div class="checkbox checkbox-theme checkbox-circle">
<input id="checkbox15" type="radio" name="lastTimeFrame" value="last24">
<label for="checkbox15">Last 24 Hours</label>
</div>
<div class="checkbox checkbox-theme checkbox-circle">
<input id="checkbox16" type="radio" name="lastTimeFrame" value="last3Days">
<label for="checkbox16">Last 3 days</label>
</div>
<div class="checkbox checkbox-theme checkbox-circle">
<input id="checkbox17" type="radio" name="lastTimeFrame" value="last7Days">
<label for="checkbox17">Last 7 days</label>
</div>
<br>
</div>
I use the framework Boostrap and I would like to control the radio buttons alignement.
All the examples I saw to display a responsive list of radio buttons do not manage the alignment. Either they were using labels with same size or a fixed width that keep the alignment but nothing really responsive.
I've tried to use the solution below but with
http://jsfiddle.net/rm7n73ep/`
<label class="radio-inline">
<input type="radio" name="inlineRadioOptions" id="inlineRadio2" value="option2">
Radio button's label 2
Does somebody know how to combine the property for the responsive behavior and for a correct alignment of labels and radio button?
Thanks a lot for your answer!
Add the following class
label{
display: block;
}
Check if this helps :
<div class="form-group">
<label class="col-md-5"> Your label </label>
<div class="col-md-7">
<div class="col-md-6">
<input type="radio" name="name1" value="0" checked/>
<label for="name1">Input 1</label>
<input type="radio" name="name2" value="1" />
<label for="name2">Input2</label>
</div>
</div>
</div>
I would like to use these funky radio buttons though the radio buttons have an id=radio1, id=radio2, id=radio3 etc
I would like all of them to have id-radio1 so it writes the result to radio1 in the database:
Here is how I have normal radio buttons working in the past using the same id and they toggle between one another:
<div class="form-group col-md-12">
<label class="control-label form-check-inline">Gender</label>*
<div class="form-group">
<input type="radio" id="Gender" name="Gender" value="M" required="required" /><label class="control-label">Male</label>
<input type="radio" id="Gender" name="Gender" value="F" required="required" /><label class="control-label">Female</label>
</div>
</div>
$Gender=$_POST["Gender"];
INSERT INTO [dbo].[SubmissionsTBL]
[Gender]
VALUES
(,'".trimText($Gender)."')
Though, with the funky radio buttons chaning from this:
<div class="funkyradio">
<div class="funkyradio-primary col-md-6">
<input type="radio" name="radio" id="radio1" />
<label for="radio1">Male</label>
</div>
<div class="funkyradio-primary col-md-6">
<input type="radio" name="radio" id="radio2"/>
<label for="radio2">Female</label>
</div>
</div>
to this doesn't work - it doesn't allow me to toggle radio buttons:
<div class="funkyradio">
<div class="funkyradio-primary col-md-6">
<input type="radio" name="radio" id="radio1" />
<label for="radio1">Male</label>
</div>
<div class="funkyradio-primary col-md-6">
<input type="radio" name="radio" id="radio1"/>
<label for="radio2">Female</label>
</div>
</div>
What is stopping the toggle?
Thank you!
TL;DR: Due to the id and name attribute having the same value in your first example, I believe you may be confusing the two. With the database communication code you put up, it's grabbing the name="Gender" and not the id="Gender".
Additional information about id and class though you might find useful as an internet programmer:
The id attribute can only apply to one element per HTML document. I would suggest using the class attribute instead. The main difference between and id and a class is that a class can be applied to multiple elements.
Here is a working solution to the code you provided:
<div class="funkyradio">
<div class="funkyradio-primary col-md-6">
<input type="radio" name="radio1" id="radio1" class="radio_grp1"/>
<label for="radio1">Male</label>
</div>
<div class="funkyradio-primary col-md-6">
<input type="radio" name="radio1" id="radio2" class="radio_grp1"/>
<label for="radio2">Female</label>
</div>
</div>
I used the class .radio_grp1 as the name so that you know that you're referring to a group of radio buttons rather than just one.
Moreover, if you're using a library like bootstrap, it's very common that an element will already have an assigned class. To solve this issue, you can assign a single element multiple classes by adding a space in the string following the class attribute like so:
<input type="radio" name="radio" id="radio2" class="radio radio_grp1"/>
Hope this was useful!
Your code should be changed to something like this. the radio button's name is what is submitted to the back end, and the id is used for front-end things like label association.
id's should always be unique.
<div class="funkyradio">
<div class="funkyradio-primary col-md-6">
<input type="radio" name="radio1" id="radio1" />
<label for="radio1">Male</label>
</div>
<div class="funkyradio-primary col-md-6">
<input type="radio" name="radio1" id="radio2"/>
<label for="radio2">Female</label>
</div>
</div>
If by toggling, you mean the normal behavior of radio buttons, then that happens whenever all the radio buttons in the group have the same name.
Using jQuery Mobile and Horizontal radio field sets as show at:
http://demos.jquerymobile.com/1.4.3/checkboxradio-radio/#Horizontalgroup
What's the proper way to write two (or many) different radio groups into a single fieldset (if possible). Writing multiple horizontal radio groups into a single fieldset seems strange to me. I'm not sure if I'm using all the elements properly.
<div data-role="page" id="test">
<div data-role="content">
<div data-role="fieldcontain">
<div class="ui-body ui-body-a ui-corner-all">
<fieldset data-role="controlgroup" data-theme="a" data-type="horizontal">
<legend>FieldSet Name:</legend>
<div class="ui-field-contain">
<legend>Question 1:</legend>
<input type="radio" name="radio-choice-1" id="radio-choice-1-no" value="1">
<label for="radio-choice-1-no">No</label>
<input type="radio" name="radio-choice-1" id="radio-choice-1-yes" value="2">
<label for="radio-choice-1-yes">Yes</label>
</div>
<div class="ui-field-contain">
<legend>Question 2:</legend>
<input type="radio" name="radio-choice-2" id="radio-choice-2-no" value="1">
<label for="radio-choice-2-no">No</label>
<input type="radio" name="radio-choice-2" id="radio-choice-2-yes" value="2">
<label for="radio-choice-2-yes">Yes</label>
</div>
</fieldset>
</div>
</div>
</div>
In the HTML layout shown in the following screenshot, I want the radio buttons exactly under the Yes and No labels, but the CSS padding property does not seem to apply to the HTML input tag. The code is given.
How can I change the inline style so that the radio buttons are under the Yes and No labels.
JSFiddle here.
<html>
<div style="padding:25px;">
<div style="background-color:#bf5b5b; ">
<label style="padding-left:25px; padding-right:25px;">Yes</label>
<label style="padding-left:25px; padding-right:25px;">No</label>
<label style="padding-left:25px; padding-right:25px;"></label>
</div>
<div id="option_one_div" style="background-color:#74d4dd;">
<input style="padding-left:125px; padding-right:25px;" type="radio" name="radio" value="0">
<input style="padding-left:25px; padding-right:25px;" type="radio" name="radio" value="1">
<label style="padding-left:25px; padding-right:25px;" for="option_one_div">Label of first group of Radio Buttons</label>
</div>
<div id="option_two_div" style="background-color:#36d666;">
<input style="padding-left:25px; padding-right:25px;" type="radio" name="radio" value="0">
<input style="padding-left:25px; padding-right:25px;" type="radio" name="radio" value="1">
<label style="padding-left:25px; padding-right:25px;" for="option_two_div">Label of second group of Radio Buttons</label>
</div>
</div>
</html>
The idea of padding is that it adds space within the element. You appear to be trying to add space outside the element, for which you should be using margin.
This image may help to explain the concept.
(source: w3schools.com)
The point is, to add space around an element you'd normally use margin rather than padding.
On a side note, a lot of people make this mistake when adding padding to the body; they use margin instead and it yields unpredictable results).
Here's an example fiddle using your code, just with margin instead of padding (I modified the pixels to make it work properly).
Put span tag around input tags with left-padding:
Here is the JSFiddle
Here's my Fiddle
<input style="margin-left: 5%; padding-left:25px; padding-right:25px;" type="radio" name="radio" value="0">
<input style="margin-left: 7.5%; padding-left:25px; padding-right:25px;" type="radio" name="radio" value="1">
I used margin-left with percentage values. It looks like what you described you wanted - you can always replace percentage with pixel values if needed.
In your 2nd div i.e.
<div id="option_one_div" style="background-color:#74d4dd;">
the
<input style="padding-left:125px; padding-right:25px;" type="radio" name="radio" value="0">
here padding-left has 125 px. change it to 25 px your prob will be solved.
Hi why not just do this:
<html>
<div>
<div style="background-color:#bf5b5b; width:100%; float:left;">
<label style="width:15%; padding-left:3%">Yes<input type="radio" name="radio" value="0"></label>
<label style="width:15%;">No<input type="radio" name="radio" value="0"></label>
<label style="width:60%;">Label of first group of Radio Buttons</label>
</div>
<div style="background-color:#74d4dd; width:100%; float:left;">
<label style="width:15%; padding-left:3%">Yes<input type="radio" name="radio" value="0"></label>
<label style="width:15%;">No<input type="radio" name="radio" value="0"></label>
<label style="width:60%;">Label of teo group of Radio Buttons</label>
</div>
<div style="background-color:#36d666; width:100%; float:left;">
<label style="width:15%; padding-left:3%">Yes<input type="radio" name="radio" value="0"></label>
<label style="width:15%;">No<input type="radio" name="radio" value="0"></label>
<label style="width:60%;">Label of three group of Radio Buttons</label>
</div>
</div>
</html>
Then just add some # media css classes to make it full mobile responsive and stack-able too.
This will offer much more to you prospective site users as they can view it from their mobile devices with as much ease as they can from a pc.