Here is my HTML and CSS
.input[type="radio"] {
margin-left: -30px;
}
<div>
<input type="radio" name="num" value="1"><label>Label1</label>
<input type="radio" name="num" value="2"><label>Label2</label>
<input type="radio" name="num" value="3"><label>Label3</label>
<input type="radio" name="num" value="4"><label>Label4</label>
<input type="radio" name="num" value="5"><label>Label5</label>
</div>
How do I change the horizontal spacing between the radio button and the text? I'd like the text to be further to the radio button.
There you go:
The name must be the same for all radio buttons to toggle only one of them.
The class sets the right margin to 0.
And the id on the input is linked with the for attribute on the label so you can toggle the radio button by clicking the label too.
.mr0 {
margin-right: 0px;
}
<div>
<input type="radio" name="label" value="1" class="mr0" id="1"><label for="1">Label1</label>
<input type="radio" name="label" value="2" class="mr0" id="2"><label for="2">Label2</label>
<input type="radio" name="label" value="3" class="mr0" id="3"><label for="3">Label3</label>
<input type="radio" name="label" value="4" class="mr0" id="4"><label for="4">Label4</label>
<input type="radio" name="label" value="5" class="mr0" id="5"><label for="5">Label5</label>
</div>
Related
Is it possible to have multiple radio button groups in a single form? Usually selecting one button deselects the previous, I just need to have one of a group deselected.
<form>
<fieldset id="group1">
<input type="radio" value="">
<input type="radio" value="">
</fieldset>
<fieldset id="group2">
<input type="radio" value="">
<input type="radio" value="">
<input type="radio" value="">
</fieldset>
</form>
Set equal name attributes to create a group;
<form>
<fieldset id="group1">
<input type="radio" name="group1">value1</input>
<input type="radio" name="group1">value2</input>
</fieldset>
<fieldset id="group2">
<input type="radio" name="group2">value1</input>
<input type="radio" name="group2">value2</input>
<input type="radio" name="group2">value3</input>
</fieldset>
</form>
This is very simple you need to keep different names of every radio input group.
<input type="radio" name="price">Thousand<br>
<input type="radio" name="price">Lakh<br>
<input type="radio" name="price">Crore
</br><hr>
<input type="radio" name="gender">Male<br>
<input type="radio" name="gender">Female<br>
<input type="radio" name="gender">Other
Just do one thing,
We need to set the name property for the same types. for eg.
Try below:
<form>
<div id="group1">
<input type="radio" value="val1" name="group1">
<input type="radio" value="val2" name="group1">
</div>
</form>
And also we can do it in angular1,angular 2 or in jquery also.
<div *ngFor="let option of question.options; index as j">
<input type="radio" name="option{{j}}" value="option{{j}}" (click)="checkAnswer(j+1)">{{option}}
</div>
in input field make name same
like
<input type="radio" name="option" value="option1">
<input type="radio" name="option" value="option2" >
<input type="radio" name="option" value="option3" >
<input type="radio" name="option" value="option3" >
To create a group of inputs you can create a custom html element
window.customElements.define('radio-group', RadioGroup);
https://gist.github.com/robdodson/85deb2f821f9beb2ed1ce049f6a6ed47
to keep selected option in each group, you need to add name attribute to inputs in group, if you not add it then all is one group.
So Im a complete beginner and Im stuck on some personal project. Im making forms and I want to have inputs from radio buttons all in the same line, but under the label. I know how to make all elements inline and I know that setting the block property should put them under label. But block element puts all of the inputs on its on line. What I want is all inputs to be on the same line, under lable. I can use tag in HTML, but I want to make it with CSS. Any tips?
<div class="radio" >
<label class="radio" for="age">Your age:</label>
<input type="radio" name="age">0-20
<input type="radio" name="age">20-40
<input type="radio" name="age">40-60
<input type="radio" name="age">60-80
<input type="radio" name="age">80-100
</div>
<div class="radio" >
<label class="radio" for="gender">Your gender</label>
<input type="radio" name="gender">Male
<input type="radio" name="gender">Female
</div>
just put a line break <br />
<div class="radio" >
<label class="radio" for="age">Your age:</label>
<br />
<input type="radio" name="age">0-20
<input type="radio" name="age">20-40
<input type="radio" name="age">40-60
<input type="radio" name="age">60-80
<input type="radio" name="age">80-100
</div>
<div class="radio" >
<label class="radio" for="gender">Your gender</label>
<br />
<input type="radio" name="gender">Male
<input type="radio" name="gender">Female
</div>
Set the label to display: flex; but make sure not to target the radio class or it will also effect the parent div and not work properly.
Instead of setting all of the radio buttons to display: block, setting just the label to display: block will get the effect you want. Block elements will start a new line (if needed) and force the next element to a new line as well. Since you want just the label to be on a new line by itself, setting it to display: block will do the trick.
label.radio {
display: block;
}
<div class="radio">
<label class="radio" for="age">Your age:</label>
<input type="radio" name="age">0-20
<input type="radio" name="age">20-40
<input type="radio" name="age">40-60
<input type="radio" name="age">60-80
<input type="radio" name="age">80-100
</div>
<div class="radio">
<label class="radio" for="gender">Your gender</label>
<input type="radio" name="gender">Male
<input type="radio" name="gender">Female
</div>
Is it possible to have multiple radio button groups in a single form? Usually selecting one button deselects the previous, I just need to have one of a group deselected.
<form>
<fieldset id="group1">
<input type="radio" value="">
<input type="radio" value="">
</fieldset>
<fieldset id="group2">
<input type="radio" value="">
<input type="radio" value="">
<input type="radio" value="">
</fieldset>
</form>
Set equal name attributes to create a group;
<form>
<fieldset id="group1">
<input type="radio" name="group1">value1</input>
<input type="radio" name="group1">value2</input>
</fieldset>
<fieldset id="group2">
<input type="radio" name="group2">value1</input>
<input type="radio" name="group2">value2</input>
<input type="radio" name="group2">value3</input>
</fieldset>
</form>
This is very simple you need to keep different names of every radio input group.
<input type="radio" name="price">Thousand<br>
<input type="radio" name="price">Lakh<br>
<input type="radio" name="price">Crore
</br><hr>
<input type="radio" name="gender">Male<br>
<input type="radio" name="gender">Female<br>
<input type="radio" name="gender">Other
Just do one thing,
We need to set the name property for the same types. for eg.
Try below:
<form>
<div id="group1">
<input type="radio" value="val1" name="group1">
<input type="radio" value="val2" name="group1">
</div>
</form>
And also we can do it in angular1,angular 2 or in jquery also.
<div *ngFor="let option of question.options; index as j">
<input type="radio" name="option{{j}}" value="option{{j}}" (click)="checkAnswer(j+1)">{{option}}
</div>
in input field make name same
like
<input type="radio" name="option" value="option1">
<input type="radio" name="option" value="option2" >
<input type="radio" name="option" value="option3" >
<input type="radio" name="option" value="option3" >
To create a group of inputs you can create a custom html element
window.customElements.define('radio-group', RadioGroup);
https://gist.github.com/robdodson/85deb2f821f9beb2ed1ce049f6a6ed47
to keep selected option in each group, you need to add name attribute to inputs in group, if you not add it then all is one group.
I have a horizontal radio button widget in my page that looks like this:
<form>
<fieldset data-role="controlgroup" data-type="horizontal" data-mini="true">
<input name="tool-selector" id="tool-selector-1" value="1" type="radio" checked>
<label for="tool-selector-1">1</label>
<input name="tool-selector" id="tool-selector-2" value="2" type="radio">
<label for="tool-selector-2">2</label>
<input name="tool-selector" id="tool-selector-3" value="3" type="radio">
<label for="tool-selector-3">3</label>
<input name="tool-selector" id="tool-selector-4" value="4" type="radio">
<label for="tool-selector-4">4</label>
<input name="tool-selector" id="tool-selector-5" value="5" type="radio">
<label for="tool-selector-5">5</label>
<input name="tool-selector" id="tool-selector-6" value="6" type="radio">
<label for="tool-selector-6">6</label>
<input name="tool-selector" id="tool-selector-7" value="7" type="radio">
<label for="tool-selector-7">7</label>
</fieldset>
</form>
I want it to always span the page width instead of not reaching to the end of the line if the screen is too wide or overflowing to the next line if it is too narrow. Is this possible, and if so, how can it be done?
Thanks.
Working example: http://jsfiddle.net/Gajotres/4KahY/
HTML:
<form>
<fieldset data-role="controlgroup" data-type="horizontal" data-mini="true">
<input name="tool-selector" id="tool-selector-1" value="1" type="radio" checked>
<label for="tool-selector-1">1</label>
<input name="tool-selector" id="tool-selector-2" value="2" type="radio">
<label for="tool-selector-2">2</label>
<input name="tool-selector" id="tool-selector-3" value="3" type="radio">
<label for="tool-selector-3">3</label>
<input name="tool-selector" id="tool-selector-4" value="4" type="radio">
<label for="tool-selector-4">4</label>
<input name="tool-selector" id="tool-selector-5" value="5" type="radio">
<label for="tool-selector-5">5</label>
<input name="tool-selector" id="tool-selector-6" value="6" type="radio">
<label for="tool-selector-6">6</label>
<input name="tool-selector" id="tool-selector-7" value="7" type="radio">
<label for="tool-selector-7">7</label>
</fieldset>
</form>
JavaScript:
.ui-controlgroup-controls {
width: 100% !important;
}
// This number shoud reflect 100 divided with number of controlgroup radio elements
.ui-controlgroup-controls .ui-radio {
width: 14.25% !important;
}
.ui-controlgroup-controls .ui-radio label {
text-align: center !important;
}
The below HTML code i have allows multiple selection of radio button ? How do i limit it so that only one can be chooses at a time from the list
<fieldset data-role="controlgroup">
<legend></legend>
<label for="Arrived/Left">Arrived/Left Destination</label>
<input type="radio" name="Arrived/Left" id="Arrived/Left" value="Arrived/Left">
<label for="Delayed">Delayed</label>
<input type="radio" name="Delayed" id="Delayed" value="Delayed">
<label for="Canceled">Canceled</label>
<input type="radio" name="Canceled" id="Canceled" value="Canceled">
<label for="getupdate">Post to Get Update ?</label>
<input type="radio" name="getupdate" id="getupdate" value="getupdate">
<label for="Other">Other</label>
<input type="radio" name="Other" id="Other" value="Other">
</fieldset>
First this is not jQuery.. this is HTML..
Second you can do that by giving all the radio buttons of the same group (where you want only one to be selected) the same name..
<fieldset data-role="controlgroup">
<legend></legend>
<label for="Arrived/Left">Arrived/Left Destination</label>
<input type="radio" name="status" id="Arrived/Left" value="Arrived/Left">
<label for="Delayed">Delayed</label>
<input type="radio" name="status" id="Delayed" value="Delayed">
<label for="Canceled">Canceled</label>
<input type="radio" name="status" id="Canceled" value="Canceled">
<label for="getupdate">Post to Get Update ?</label>
<input type="radio" name="status" id="getupdate" value="getupdate">
<label for="Other">Other</label>
<input type="radio" name="status" id="Other" value="Other">
</fieldset>
use name attribute to group your radio button
<fieldset data-role="controlgroup">
<legend></legend>
<label for="Arrived/Left">Arrived/Left Destination</label>
<input type="radio" name="status" id="Arrived/Left" value="Arrived/Left">
<label for="Delayed">Delayed</label>
<input type="radio" name="status" id="Delayed" value="Delayed">
<label for="Canceled">Canceled</label>
<input type="radio" name="status" id="Canceled" value="Canceled">
<label for="getupdate">Post to Get Update ?</label>
<input type="radio" name="status" id="getupdate" value="getupdate">
<label for="Other">Other</label>
<input type="radio" name="status" id="Other" value="Other">
</fieldset>
You define radio button groups with the name property (radio buttons with the same name belong to the same group).
You are having a different name for each of your radio. Change the names of all the input radio to a single name. The radios having the same name will behave as a single group which is what your requirement.
*You haven't closed the input tags.
Hope this helps.