Here is a method of HTML mark-up css and JS which allow your forms to be suited for any occasion, slim or wide the controls slip about to fit neatly in the space available.
with multiple sections and multiple control rows...




The form is able to resize down to the width of the widest single element by popping the elements down a row when width gets too restricted. This is done by a three line attack, HTML, CSS and finally JS.
The mark-up is structured like so
FORM
+ FIELDSET
+ OL
+ LI
+ DIV.control+ LABEL
+ DIV.fIeld+ DIV.control
+ LABEL
+ DIV.fIeld+ LI
+ FIELDSET
+ OL
Each control is a label and div containing the field, this allows both elements to move as one when popping on to a new row. It also allows for percentage widths to be placed on the DIV.control to line up the controls nicely.
An ordered list give us the rows and fieldsets the sections.
The control CSS provides a container for the Label and DIV.field, where you set the width and the contents flow to take up the available space.

fieldset .control
{
float:left;
padding:.4em 0 .1em;
}
fieldset .control label
{
float:left;
width:5.5em;
text-align:right;
}
fieldset .field
{
margin-left:6em;
margin-right:1em;
}Each control is floated left, and you can add your own breaks to define the controls position with in each row.
At this point when you shink the form the CSS can handle getting every control onto a separate row (fig 2 and 3) but to get the full shrinkage we need to use a bit of JS
Guess what, I'm going to use jQuery here, this will check the widths of the form and the controls and change their CSS or add a CSS class where needed
$(window)
.ready(setForm)
.resize(setForm);
function setForm() {
$("form").each(function () {
var $el = $(this);
if ($el.width() < 280) {
$el.addClass("narrow");
} else {
$el.removeClass("narrow");
}
});
$(".control").each(function () {
var $el = $(this);
if ($el.hasClass("w50")) {
$el.css("width","")
if($el.width() < 250) $el.css("width", "100%");
}
});
}I've plopped this all into a single file ('ceptin jQuery which is on the ms CDN) for you to squeeze until its i's pop out of its <head> (urgg)
| < | May 2012 | |||||
|---|---|---|---|---|---|---|
| S | M | T | W | T | F | S |
| 29 | 30 | 1 | 2 | 3 | 4 | 5 |
| 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| 13 | 14 | 15 | 16 | 17 | 18 | 19 |
| 20 | 21 | 22 | 23 | 24 | 25 | 26 |
| 27 | 28 | 29 | 30 | 31 | 1 | 2 |
Add-ins AJAX ASP.NET MVC Browsers C# Caching CodeDom Compression CORS CSS CV Data Database DependencyResolver Development Dynamic Entity Framework Error Handling Extend File Upload Forms GDI+ HTML HTML Editor HTTP Interfaces JavaScript JQuery MCE MetadataProvider MSBuild Numbers Objects Patterns Progressive Enhancement Projects Publish Regex Resources Security SEO SMTP Source Control Strings Sub-Collections TDD Templates Tools Twitter User Interface WCF Web Development WHS WMC XLinq XML
15/05/2012
WindowsAzure
Announcing the MEET Windows Azure Event! Streamed online June 7th. Register at http://t.co/bObzTAuL #MEETAzure #WindowsAzure
10/05/2012
kevinwhinnery
Comparing Titanium and PhoneGap - A common question I get asked at developer events and conferences is how... http://t.co/Zq2eND6B
09/05/2012
brianleroux
PhoneGap goals and philosophy: http://t.co/wkq8wI2T
just now
satonaoki
RT @WindowsAzure: The Bing Search API on #WindowsAzure Marketplace is Here! http://t.co/GLILFMYe
just now
itsacloudyworld
Latest The Bing Search API on Windows Azure Marketplace is Here! http://t.co/S9K9cRwm