Forum Moderators: open
<label for="fname">First Name:</label>
<input type="text" id="fname" name="firstname" maxlength="30">
My question deals with the "for" attribute and how to use it when your label is for more than one input. (i.e Language: Eng or Fre).
<label for="lang">Language:</label>
<input type="radio" id="lang"> Eng
<input type="radio" id="lang"> Fre
One can't have more than one id...so?
<fieldset>
<legend>Language:</legend>
<input type="radio" name="lang" id="eng" value="eng"> <label for="eng">Eng</label>
<input type="radio" name="lang" id="fre" value="fre"> <label for="fre">Fre</label>
</fieldset>
Labels are for individuals, fieldsets are for groups. The legend is the the label for the group.
skube..
either just set those particular input id's to display: inline;
or if you have a block rule which is making your labels display: block too then you can target both the inputs and the labels through a fieldset id (making all display: inline... ) for that particular fieldset
Suzy
<style type="text/css">
legend,input,label { display:inline;}
</style>
<fieldset>
<legend>Language:</legend>
<input type="radio" name="lang" id="eng" value="eng"><label for="eng">Eng</label>
<input type="radio" name="lang" id="fre" value="fre"><label for="fre">Fre</label>
</fieldset>
But it's still appearing as:
Language:
() Eng ()Fre
Is there anything else to try?
The only way I see around this is to remove one set of tags --either "legend" or "fieldset" (or both, if you wish). Of course, part of the reason folks use these is to group the options in their own little boxes. If that's not what you want, you might not want to bother with these tags.
<style type="text/css">
div.legend,input { display:inline;}
</style>
<fieldset id="prefernces">
<div class="legend">Language:</div>
<input type="radio" name="lang" id="eng" value="eng"><label for="eng">English</label>
<input type="radio" name="lang" id="fre" value="fre"><label for="fre">French</label>
</fieldset>
What you posted will display properly (that is, it will all be in one line), but I'm not sure why you want to mess around with creating a separate "div" whose style you then have to reset to display inline.
You could simply remove the DIV tags --write "Language:" between <fieldset> and the first input. Or, if you wish to further stylize your ad hoc legend (set the font, etc), you could place it between SPAN tags (which will display inline by default.)
<style type="text/css">
div.section {border-top: 1px solid; padding:10px}
div.fieldset,div.data,div.input,div.label{float:left}
div.fieldset,div.input {width:200px}
div.label{width:200px; margin-right:10px; text-align:right }
input {margin-right:5px}
.clear{clear:both}
</style>
<div class="section">
<div class="fieldset">Preferences</div>
<div class="data">
<div class="label">Language:</div>
<div class="input">
<input type="radio" name="lang" id="eng" value="eng">English
<input type="radio" name="lang" id="fre" value="fre">French
</div>
<div class="clear"></div>
<div class="label">Preferred Salutation:</div>
<div class="input">
<input type="radio" name="salutation" id="mr" value="mr">Mr.
<input type="radio" name="salutation" id="ms" value="ms">Ms.
<input type="radio" name="salutation" id="mrs" value="mrs">Mrs.
<input type="radio" name="salutation" id="dr" value="dr">Dr.
<input type="radio" name="salutation" id="hon" value="hon">Hon.
</div>
</div>
</div>
I was trying to get around using all the divs. The above code seems a little verbose and not really as symantically correct as it could be. Unfortunately, I have no idea how else I can get the same type of alignments without using tables.
p.s. - I guess thread has now mutated back to a css issue, sorry.