...

View Full Version : align labels and inputs in a form



carlitos_way
06-27-2007, 09:41 AM
Hi all, i'm working on a project in which i have a lot of forms, and i decided to follow for all of them the same structure (using <ul><li>) you can see here:

http://www.viniolindog.it/stuff/test/utenti/utenti.html

the problem is when i try to put in the same line more inputs as i need to align them vertically with their own labels, horizontally with the other input. you can see the error i got from this image, or from the previous url:

http://www.viniolindog.it/stuff/test/images/nomeCognome.GIF

the label "cognome" should be aligned vertically with his respective input field...

how can this be done?

felgall
06-27-2007, 10:33 AM
label {display:block;width:100px;}

and set the width to what you need.

carlitos_way
06-27-2007, 11:05 AM
label {display:block;width:100px;}

and set the width to what you need.

i cannot see the difference...

_Aerospace_Eng_
06-27-2007, 11:33 AM
Whats up with the useless spans everywhere? Also whats up with the div in a span? Thats not valid. I would put the Text and the input in the same label. Float the label to the left and make the input display:block.

carlitos_way
06-27-2007, 12:55 PM
ok, the div in the span is to display some result after an ajax request.

the spans everywhere are coming from an accessify tool (http://www.accessify.com/tools-and-wizards/accessibility-tools/form-builder/) i used to write forms faster..

but i'll try what you say

I would put the Text and the input in the same label. Float the label to the left and make the input display:block.

Arbitrator
06-27-2007, 10:50 PM
the label "cognome" should be aligned vertically with his respective input field...

how can this be done?I would put the form elements in container elements and float said containers.


div { float: left; }
div * { display: block; }


<div>
<label for="nome">nome</label>
<input type="text" id="nome">
</div>
<div>
<label for="cognome">cognome</label>
<input type="text" id="cognome">
</div>

Additionally, I would fix all of the errors shown by the W3C validator (http://validator.w3.org/check?verbose=1&uri=http%3A%2F%2Fwww.viniolindog.it%2Fstuff%2Ftest%2Futenti%2Futenti.html) and those errors shown by the Validome validator (http://www.validome.org/validate/?uri=http%3A%2F%2Fwww.viniolindog.it%2Fstuff%2Ftest%2Futenti%2Futenti.html). In addition to those errors, there are some weird things going on.


Thereís a paragraph element with no content.
A form element has an empty action attribute. If youíre not going to use the attribute, you may as well omit the element or replace it with a more generic div element.
There are numerous empty value attributes. You may as well remove them since theyíre redundant.
You have redundant value attributes. <option>30</option> is the same as <option value="30">30</option>.
There are anchor elements whose only content is a no‐break space (&nbsp;) character. The character seems to serve no purpose.
Anchor elements are being used to mark up asterisk (*) characters; Iím not sure why. The generic span is probably more appropriate. Regarding accessibility, Iím not sure how screen readers are supposed to tell that the asterisk indicates a required field.
You have two buttons with the same tabindex value, the value is zero, and one wonders why the first thing you would want to access in a form are the check and reset buttons. I would expect the user to want to fill out the form first.
You have a copyright notice that doesnít state whatís copyrighted. IMO, itís strange to claim copyright over an HTML/XHTML form.

Other Issues

I would not use inline CSS for maintenance reasons. An embedded style sheet that uses the style element is better than inline CSS.
Avoid presentational elements such as br.
You may want to consider what the advantages of using XHTML are. If none, then I would recommend use of HTML instead.
mailto: (monospace) tends not to work unless the user has and uses a locally configured email program.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum