CSS about checkbox and radiobox

C

Cylix

I have a label next the the checkbox/radiobox,
but I find the label is not the same level about the box horizontally.
How can I set this in CSS?

Thank you.
 
T

Toby Inkster

Cylix said:
I have a label next the the checkbox/radiobox,
but I find the label is not the same level about the box horizontally.
How can I set this in CSS?

LABEL {
position: relative;
top: -3px; /* adjust as desired */
}
 
C

Cylix

Toby said:
LABEL {
position: relative;
top: -3px; /* adjust as desired */
}

In my code, this CSS seems set the the whole radiobox group move
upward,
But not only the label ...

My HTML code:
<label>
<input type="radio" value="gold" checked>
Gold</label>
<label>
<input type="radio" value="silver">
Silver</label>
 
T

Toby Inkster

Cylix said:
<label>
<input type="radio" value="gold" checked>
Gold</label>

Ah -- you're using implicit labels. You know, Internet Explorer doesn't
support these properly. (Surprise, surprise!)

Try:

<input name="metal" type="radio" value="gold" checked id="metal_gold">
<label for="metal_gold">Gold</label>
<input name="metal" type="radio" value="silver" id="metal_silver">
<label for="metal_silver">Silver</label>

then you can adjust the position of the label independently of its control.
 
J

Jukka K. Korpela

I wonder what was Toby's idea there. Trying to fix an assumed browser
deficiency in layout by suggesting a 3 pixels shift in some direction sounds
pretty desperate. On browsers that have an opposite deficiency or no
deficiency, you'd just make things worse.
In my code, this CSS seems set the the whole radiobox group move
upward,
But not only the label ...

Well, apparently, if the <input> element is inside the <label> element, as
you have, which is quite correct. Toby apparently assumed a different
markup, like
<input type="radio" value="gold" checked id="gold"><label
for="gold">Gold said:
My HTML code:
<label>
<input type="radio" value="gold" checked>
Gold</label>
<label>
<input type="radio" value="silver">
Silver</label>

It's not a good idea to put several radio buttons on the same line. With
just two buttons, it might work, but in a long string like
( ) foo ( ) bar ( ) zap ( ) zip ( ) abc ( ) bcd ( ) cde ( ) ...
where ( ) denotes a radio button, people may make the mistake of checking
the button _after_ the item they wish to select. Never say that nobody is
stupid or careless enough to do so. We can't make anything foolproof
(because the fools are so clever), but at least we can try to exclude some
errors that will rather _easily_ be made by anyone when a little tired or in
haste.

So put them on separate lines, whatever markup you use for it (<div> is my
favorite).

The original problem of vertical alignment remains. The problem is that I do
not see the problem. On which browser do you see that "the label is not the
same level about the box horizontally"? Please post a sample URL, too. Maybe
it's something in the markup as a whole, or in the stylesheet.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top