Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Forms, CSS or Tabular?

Featured Replies

What is the best way to layout contact forms.

 

 

And how does the CSS work for forms?

 

 

Many Thanks Ben

I think this is essentially the general question: do you use tables to layout data which isn't strictly tabular? And the answer is: no in principle, but often yes in practise. While CSS has all the necessary properties to use tabular layouts in <div>s etc., browser support is sketchy. So when I can trust a layout mechanism that has been used for a decade against one which is hardly supported, I know which one I'll choose ;) I don't like it, but I'm not terribly convinced by any other approaches yet. I'd like to hear some other ideas for getting round the tabular layout problem though (without laying out each individual component by giving it left/top/width/height settings).

 

BTW, I never use tables or (i)frames to layout entire pages. I think we're talking about mini-structures in the page here, not entire page layout containers, which can be done easily in CSS since there usually aren't many <div>s to style in that case.

  • Author

I'll do it tabular to start with then once i mastered the layout for Pure CSS i will do it that way..

 

thanks bluedreamer, need that member of the month back hey?

I use div's for contact forms. You should REALLY learn div's, I think they are easier than tables...

There's really no justification for presenting forms as tabular data :)

I've taken a look at the link you gave... while they look impressive, I'm worried by the lists of bugs and workarounds suggested for many. In the first case, "Prettier Accessible Forms", he use an ordered list to structure the content, and says the list "is, in [his] opinion, semantically appropriate (i.e. a list of form controls in some kind of logical order)". I think one could argue a table is also semantically appropriate: a <th> denotes a heading, which can be a row heading of course. So if a <th> in a row contains a <label>, that's really enforcing that the table has row titles on the left, and data to be completed on the right... sounds a bit like a spreadsheet with only one column! Which is logical and conveys real meaning. At least as much as an ordered list anyway.

 

In another case, "CSS-Only, Table-less Forms", the legends are laid out using "display:block" and "width:130px", quite a common approach. But the former doesn't work in some older browsers (still used by a small percentage of the market, granted it's very small though) and the latter doesn't lay the page out correctly if the user overrides the font-size for accessibility reasons. AFAIK, "px" measurements are generally discouraged anyway; last I heard, relative units are preferred, but render slightly differently between IE and FF. So again, not totally secure with this concept.

 

Tabular layouts are ideal because they're flexible, and can resize down the entire column if the font-size or content of the cells changes. Just those in CSS aren't supported in IE (before IE8b2 anyway), which is the dominant browser. So that's my justification why, unfortunately, tables still have their place in some mini-layouts. Now if all versions of IE were overnight consistent with FF one might stand a chance :rolleyes:

While CSS has all the necessary properties to use tabular layouts in <div>s etc., browser support is sketchy. So when I can trust a layout mechanism that has been used for a decade against one which is hardly supported, I know which one I'll choose

 

Um...what are you talking about? CSS has been fully supported in all major browsers for well over 5 years, even IE6 has decent (if a little quirky) support for CSS layout, there is absolutely NO reason to use tables to layout anything except tabular data.

 

 

I'd like to hear some other ideas for getting round the tabular layout problem though (without laying out each individual component by giving it left/top/width/height settings).

 

How about using 'float', makes laying out forms and aother such items very easy.

 

irn3rd, laying out forms with CSS is a simple case of seperating elements into blocks and positioning them using the float property and margins/padding. It's worth learning now because it wont take long if your familiar with CSS and it gives you far greater flexibility. If you like I can post a simple example up here?

Um...what are you talking about? CSS has been fully supported in all major browsers for well over 5 years, even IE6 has decent (if a little quirky) support for CSS layout

Ah, but until IE8b2 there was no support for CSS2 table layouts (perhaps I should have made the '2' explicit). E.g. display:table, :table-row and :table-cell just aren't there in IE, so it is impossible to do "self-expanding" table layouts (i.e. those which can resize a column or row when the contents change size) using <div>s and CSS. In Firefox the support is there, though pre-1.5 it used to be a bit buggy. It is now completely implemented I believe. That was my point, nothing to do with CSS support in general. I would love to move away from <table>s completely, when the support is finally there and is reliable.

 

I agree floating elements can be very useful.

...and the latter doesn't lay the page out correctly if the user overrides the font-size for accessibility reasons.

 

..and so presenting a form as a table is better in terms of accessibility? That's certainly an original argument..

I usualy use somthing along the following:

 

<style type="text/css">

label, input {display:block; } /*one per line*/

</style>

 

<form>

<p>

<label for="name">Name</label>

<input type="text" name="name" id="name" />

</p>

</form>

..and so presenting a form as a table is better in terms of accessibility? That's certainly an original argument..

So what's worse? A table which can be unambiguously linearised for aural parsers (i.e. it still makes sense when the field names and inputs are read left-to-right) and looks fine for visual rendering even at large font sizes, or a fixed-width layout scheme where text can overlap and therefore cannot be read because the user has made the text larger than the designer expected? Using a table in this manner meets all W3C Accessibility Guidelines for table usage, because it linearises in a sensible manner. Plus as I mentioned above, a table can be semantically adequate for a contact form: labels are the row headings and input fields are the data in the table (if these weren't input fields but just text, would you consider a table of contact details to be okay as a table?). There are "headings" and "data", and they correspond. That makes far more sense than using a table for laying out columns on a page, for example, which I would fiercely argue against.

I'm not sure if I'm reading that correctly.. a form laid out in that way would be easy enough to create in CSS, wouldn't it?

 

But even if it wasn't, it strikes me that it's just another kind of workaround. It isn't tabular data, so really it shouldn't be marked up as such (I'd say the same thing about the <li> method mentioned). It's trying to shoehorn stuff into inappropriate markup - for what? Presentation? What happened to form coming from function?

  • Author

Right, To much to read in a short time so, this is what i'm going to do and ask..

 

First of all im going to do a tabular contact form so i can at least get it running at eh minimum standards

 

Then im going to produce a CSS form, but can someone give me the CSS;

 

Cant remember what they are called like

 

body{

}

 

them things but for form objects mainly, textbox drop down menu, tick box radio button, and fields sets.

 

Thanks for all the info and arguments ill read over them properly when i have more time.

 

 

Ben

form, fieldset, legend, label, select, textarea and input are the elements to which you refer. These are the correct items to use. See this as a reference point.

 

Sticking a form in a table is most definitely not the way to go from an accessibility or a semantic HTML perspective. Neither is having multiple DIVs or spurious paragraph elements. Using the right elements as I listed above will mean the form works for all browsers and assistive technology such as a screen reader. As for browser fixes, you should never aim to get the exact same look and feel in all browsers. You're likely to waste a huge amount of time and ensure a trip to the looney bin. What you should aim for is to offer a great experience for people using modern browsers and a lesser offering (if necessary) which still allows one to access the content, in older browsers.

I asked this question myself, and on doing some research, found that many, many of the 'Pure CSS' methods were not semantic, and often as bloated as a table layout in terms of coding.

 

I'd recommend this:

 

Create the form using only the appropriate HTML elements (i.e: Fieldset, Label, Legend etc. etc) and see what that gives you. Then, apply some CSS rules directly to those elements (instead of arbitrary <li> or <dl>) tags. I also use the fieldset element (as opposed to <div> or <p>) to group the main form and subsections.

I think this rule applies across the board with making semantic XHTML, code the HTML first - without divs, layout or graphics - then apply divs and classes as necessary to layout the data. Finally, theme the layout with some graphics.

 

This series of tutorials is really good for getting the lowdown on standards compliant forms.

http://www.webstandards.org/learn/tutorial...forms/beginner/

 

and this place is an absolute godsend for seeing a variety of methods for different web elements.

http://patterntap.com/collections/

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.