Well, you could put a br tag - but please don’t - they should be used to separate text, not style page elements.
The better way is to use CSS to style it the way you want it to look.
It’s OK to do horizontal or vertical, or even a mixture if it makes sense. There have been lots of studies that suggest having LABELs on top is advantageous…
As far as marking up HTML there’s no right or wrong way, though I’m currently favouring using definition lists… eg
I liked DL’s for many things, though I don’t use them for forms for at least 2 reasons:
I avoid lists in forms
I often need to be able to do something with the label-input pair as a unit, which means I need some single thing to be able to wrap them, like a div. DL’s can only have dt’s and dd’s as children, though you can pretty much stuff anything into a dd.
Hi Stomme poes,
I started my form with pairs of “label/input” but it didn’t pass validation with a remark such as “label and inputs cannot be desendants of an element”.
I don’t think there’s an all-round perfect/best method for arranging form inputs. If you’re hand coding a form then you can obviously use any sort of container, but when using a CMS with looping fields it can get messy trying to have different containers for different input variations.
“label and inputs cannot be desendants of an element”.
That’s simply because, in HTML4, those inline elements may not be direct descendants (they can be descendants/grand children, but not direct ones) of a form.
Wrapping anything block-y around them will fix that error message. As XHTMLcoder said, fieldset works.
<form method=“get” action=“”>
<fieldset>
<legend>According to HTML4, should be first child of a fieldset, but this was dropped in XHTML and HTML5</legend>
<label for=“foo”>Foo: </label>
<input id=“foo” name=“foo”>
<label for=“bar”>Bar: </label>
<input id=“bar” name=“bar”>
<input type=“submit” value=“Baz!”>
</fieldset>
</form>
That’s perfectly legal, but what I usually want as CSS hooks is something that can make the label-input pair a unit.
Even when the design from the designer doesn’t require this, I know if I have it I can adjust the style later if needed.
Though with a DL you can easily do top-bottom and side-by-side (with the ability to use vertical-align which is really nice if your dt label wraps and you need the dd input to align with the bottom of the label, the natural eyetracking path), but since with a div-or-whatever unit I can pretty much to the same by manipulating the label into block or inline-block or even float elements.
We make some of our forms using WTForms and the previous developer used lists (just ul’s), which is nasty because generated forms are usually stupid and for example, I had to write some silly logic in our templates to ensure that radios and checkboxes followed the usual order of input-first. Generated forms are supposed to save the developer time, but I think they still suck
Attached is a screen shot of the errors displayed by the validator
As you see “fieldset” is not the solution but i guess “dl” neither. I need a more insight knowledge of where I can insert a “form” and how
Thanks
Your Anchors are the culprit and I very much doubt they were needed to wrap any block items at all and they wouldn’t be able to contain LABEL as direct decadent.