Am I breaking some unwritten rule of the Universe by having vertically positioned Radio Buttons on a form?
None that Iâm aware. Youâll frequently find radio buttons laid out like that for a poll, for example.
Nope.
Except one of the commandments written by the horizontal radio button Gods. Thatâs a pretty serious offense.
1 Like
That is what I am trying to do, for exampleâŚ
What is your favorite form of entertainment...
__ TV
__ Radio
__ Newspaper
__ Books
__ Magazines
__ Talking
I see a few personal-choice entertainment options not listed .
Radio buttons are fine. I know personally I have a hard time choosing ONE favorite thing but perhaps your client doesnât want checkboxes.
Whatâs your poison?
No, here it has to be your ONE favorite thing.
BTW, any special tips/tricks I should know about the HTML or CSS for vertical Radio Buttons?
Not particularly. Just make sure all your items are accessible (label) but other than that nothing special.
mikey_w:
Whatâs your poison?
This is a family friendly forum .
Hah!!
@RyanReese ,
What are the best styles to make the Radio Buttons vertical?
Do I want to make each one display:block ?
Some other approach?
Sorry, I havenât done CSS in a long time and it is not my strong point.
Ideally each radio will have a label, so the easiest would be doing this and making sure the label is display:block;
<label><input type="radio" name="car" value="car">Text</label>
RyanReese:
Ideally each radio will have a label, so the easiest would be doing this and making sure the label is display:block;
<label><input type="radio" name="car" value="car">Text</label>
Looking through my code-base, I found this for Gender - which is horizontalâŚ
<label class="inlineRadioLabel" for="gender_opt1">
<input id="gender_opt1" type="radio" name="gender" value="1" <?php echo (isset($gender) && $gender == "1") ? 'checked="checked"' : ''; ?>/>
Male
</label>
Do I need a for in there?
Do I need a class in there?
[quote=âmikey_w, post:10, topic:116294â]
Do I need a for in there?
[/quote]The input is nested inside, so no. You could remove that if you want. If it was <label></label><input>
then you would need the for attribute.
Depends; what does the class do? Anything important? Labels are inline by default so Iâm not surprised that is inline.
1 Like
Okay, thanks.
According to FireBug, that class just says display:inline-block, padding: 0;
I guess the answer is, âIt depends (on whether you can style it just using < label > or if you need a class to distinguish it)â
Right?
Yeah I mean it just depends on what you want.
Inline-block is basically like display:inline; but you get some functionality like setting paddings, widths, etc, etc. Also keeping the shrink-to-fit behavior that is unlike block elements.
If all elements will be vertical you could just set a class on the form and do:
.my-form label
{
display:block;
}
You have many options; choose something adn then come back if you feel like you want a review .
1 Like
Should I wrap my Radio Buttons in something?
When I look back at my code for Gender, I just had thisâŚ
<!-- Gender -->
<label for="gender">Gender:</label>
<label class="inlineRadioLabel" for="gender_opt1">
<input id="gender_opt1" type="radio" name="gender" value="1" <?php echo (isset($gender) && $gender == "1") ? 'checked="checked"' : ''; ?>/>
Male
</label>
<label class="inlineRadioLabel" for="gender_opt2">
<input id="gender_opt2" type="radio" name="gender" value="2" <?php echo (isset($gender) && $gender == "2") ? 'checked="checked"' : ''; ?>/>
Female
</label>
Your radio buttons are already wrapped in labels. What do you mean?
It seems to me that you are supposed to wrap things like Radio Buttons in some HTML âgroupâ thingâŚ
No, isnât there some âOption Groupâ thing too?
That is for drop downs, but there may be one for radio buttons tooâŚ
Optgroup is/are only for selects.