I've gotten used to using <table>s
for aligning my form fields perfectly. This is how I commonly write my forms:
<table border="0"> <tr> <td><label for="f_name">First name:</label></td> <td><input type='text' id='f_name' name='f_name' /></td> <td class='error'><?=form_error('f_name');?></td> </tr> </table>
I know this is bad practice, and I want to use CSS, <label>s
, <div>s
, or a cleaner method. However, the fact is, <table>s
work extremely well for the forms. Everything is aligned exactly right, the spacing is perfect, all errors exactly below each other, etc.
I recently tried using <dt>
and <dd>
tags for a form, but I ended up reverting back to tables just because they looked so much better.
How can I get this kind of aligned table layout without using <table>
s?
Use the CSS text-align Property to Center a Form in HTML The text-align property takes the values like left , right , center , justify , etc. We can set the value to center to center the form. For example, apply the text-align property to the form tag in the style attribute, and set the property to center .
The only way to style these elements is to use custom controls, which are created using stylable HTML elements such as div , span , etc. For example, when styling <input type="file"> , we can hide the default input and use a custom button.
Using the table tag without borders allows one to align textboxes without css.
This might not get a lot of support but here's my two cents:
In some situations tables are easier for layout; such as three columns or forms (albeit there are some great suggestions here for doing a pure css form layout so don't ignore those either.)
Processes and methodologies can make good servants but are poor masters. - Mark Dowd, John McDonald & Justin Schuh in "The Art of Software Security Assessment"
I believe that this quote very strongly applies to this situation. If your table layout is working for you, not causing accessibility issues and isn't broken - then don't fix it.
Phrases like: "you should", "must", "always" - make me scared, because one-size-doesn't-fit-all! Take zealots with a grain of salt.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With