(Dieser Artikel wurde auf Deutsch im SELFHTML aktuell Weblog veröffentlicht: »Ansatz für flexible, mehrspaltige Formulare«)
Fluid web forms?
When it comes to fit a web form into a fluid layout we usually point out several reasons why form elements should be pixel based. That is because we are totally aware of web forms being part of the browser/system and therefore do not give authority to the web designer. Sort of fundamental perception. Actually, styling web forms is hard work, even pixel sized, and could turn out into the hell of a job if specification says: make it fluid.
So, here we are and asking: why should a web form be fluid? Why go to the time and effort of develop a form that is based on input fields with flexible widths? Doesn’t make sense.
Sure it may come to make sense when the form has multiple columns and a scaling form would allow input fields to grab content that otherwise would have been cut off in a fixed pixel based form. Single-column input fields are hopefully long enough at any time, but a multi-column form may benefit from flexible widths.
One last thought: why do we go for multi-column forms instead of simple single-column ones? It’s all about conformity with user expectation (buzzword) and the use for suggestive input fields which comply with the content they may receive. For instance a submission of the user’s last name requires a longer input field than a field for the few chars of his street number. According to this idea a discrepancy between (the length of) input fields and its estimated amount of data may distract the user. As multi-column forms allow input fields with different sizes — at least our form does — they may correspond to the user’s expectation.
Approach to a flexible multi-column web form (HTML/CSS)
This is what we need:
- a wrapper that uses negative margins for left and right and therefore gets wider than the form itself. The purpose is to compensate the margins of inner elements and align them with the form.
<form class="dm_form" ..> <div class="form_wrapper"> .. </div> </form>
- embracing labels in order to get around supplemental div containers.
<label ..> (text) (input) </label>
- a bunch of spans used for titles and stuff and being abused as block elements.
<label ..> <span class="wrapper"> <span class="title">First name *</span> <input class="field" id="firstname" type="text" /> </span> </label>
CSS, code and example
See an example of the flexible form and find further information – mainly the CSS part – in the source.
Last update: August 6, 2008
The form seems to work smoothly in common browsers like Firefox, Opera (
This approach to flexible multi-column forms is released under a Whatever-you-like-to-do license and can therefore be used for whatever you like to do.
We are aware of the form not winning an award for its semantic markup. That is why we call it an »approach«. In fact it is not evil and we consider it to be a gentle way of getting a flexible and scalable form that is valid, well structured, tableless and works in common browsers.
As usual: feedback is welcome!
- November 20, 2007
Picked up some positioning problems in Apples new Safari 3 browser. Will fix it later – or even better will come up with a new approach to flexible forms.
- November 22, 2007
Up for Safari 3 now. However, a new approach definitely to come.
- July 12, 2008
Adjusted box sizing in Opera 9.
- August 6, 2008
Works fine in IE 8 now.
- March 20, 2009
Works fine in IE 8 final
nowagain: doesn’t need any specific styles, just clear out the IE 8 beta stuff now.
Related articles and yet another web forms
- The Subtraction Good Form 0.1 (Khoi Vinh)
- The Subtraction Good Form 0.2 (Thomas Maas)
- A form with style (Stu Nicholls)
- CSS-Only, Table-less Forms (Jeff Howden)
- Web Application Form Design (Luke Wroblewski)
- Accessible HTML/XHTML Forms: Beginner Level (WaSP)
- Accessible HTML/XHTML Forms: Intermediate Level (WaSP)
- Accessible HTML/XHTML Forms: Advanced Level (WaSP)
- CSS-Based Forms: Modern Solutions (Smashing Magazine)