CSS form labels

This is a discussion on "CSS form labels" within the Web Page Design section. This forum, and the thread "CSS form labels are both part of the Design Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Design Your Website > Web Page Design

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Dec 1st, 2006, 22:49
Highly Reputable Member
Join Date: Jul 2006
Location: Devon, England
Posts: 565
Thanks: 0
Thanked 0 Times in 0 Posts
CSS form labels

I am using labels to help layout the text in my forms but am wandering how I go about reducing the horizontal space between labels

Here is an example of my form

HTML: Select all
<fieldset>
    <legend><b>Image Dimensions</b></legend>
     <p><label for "Image">Image:</label>
     <input type="file" name="image"></p>
     <p><label for "percent">Resize to:</label>
     <input type="text" name="percent" size="1" /> % (percentage)</p>
     <p><label for "new_width">OR new width:</label>
     <input type="text" name="new_width" size="1" /> pixels (height will be calculated automatically)</p>
    
     <p><label for "new_height">OR new height:</label>
     <input type="text" name="new_height" size="1" /> pixels (width will be calculated automatically)</p>      
</fieldset>
I would like the gaps between each of the form elements to be reduced.

I also have another question becuase I presume you can't use a table within a form properly.

How would I go about displaying the same effect as this but using CSS?

HTML: Select all
<tr> 
                <th>OR new height and new width: </th> 
                <td> 
                    <table> 
                        <tr><td>width:</td><td><input type="text" name="width" size="1" /> pixels</td></tr> 
                        <tr><td>height:</td><td><input type="text" name="height" size="1" /> pixels</td></tr> 
                    </table> 
                </td> 
            </tr>
Any help is much appreciated
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Dec 11th, 2006, 16:02
Reputable Member
Join Date: May 2006
Location: Northampton, UK
Posts: 399
Thanks: 0
Thanked 0 Times in 0 Posts
Re: CSS form labels

personally i tend to use tables to lay forms out, simply because i veiw them as verging on tabular data.

Doing it with CSS wouldnt be difficult, i should imaging the html would look something like this:
Code: Select all
<div id="divform">

<div id="divfieldone">
<div id="field1left">
</div>
<div id="field1right>
</div>
</div>

<div id="divfieldtwo">
<div id="field2left">
</div>
<div id="field2right>
</div>
</div>

<div id="divfieldthree">
<div id="field3left">
</div>
<div id="field3right>
</div>
</div>

</div>
As for the CSS to get these to lay out like a table........ id have to actually buid it to see ... maybe someone else can help ?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Dec 12th, 2006, 11:58
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Re: CSS form labels

Your code as shown will not form an association between the label and input elements. The value of the 'for' attribute of the label should match the 'id' value of the input but you only have 'name' attributes and not 'id's.

You can adjust the spacing between labels and their respective inputs and between lines of labels and inputes by using margin and/or padding attributes.

You should not need to use a table to layout your form but some people do find this easier. Some also use the method where each line of the form is enclosed in a <div> element.

Feel free to look at the xhtml and css behind this form: http://1ontheweb.net/enquiries.html
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Dec 13th, 2006, 03:05
Elite Veteran
Join Date: Aug 2005
Location: That Place
Posts: 2,044
Blog Entries: 1
Thanks: 0
Thanked 37 Times in 37 Posts
Re: CSS form labels

Also I think there is an issue with Safari where the label has to wrap the entire input.. woot!
__________________

Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Dec 13th, 2006, 07:36
Ryan Fait's Avatar
Elite Veteran
Join Date: May 2006
Location: Las Vegas
Posts: 3,787
Thanks: 0
Thanked 0 Times in 0 Posts
Re: CSS form labels

Yeah, that's what I've always done. It seems weird, but the validator doesn't hiccup.

<label for="name">Name: <input type="text" id="name" name="name" /></label>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Dec 13th, 2006, 08:58
Reputable Member
Join Date: Jul 2006
Location: Scotland
Age: 22
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Re: CSS form labels

AListApart has a great article on making forms without tables:
http://alistapart.com/articles/practicalcss

This one is a bit scarier:
http://alistapart.com/articles/prettyaccessibleforms

I'm not sure about tables with forms... they don't sound like tabular data to me! But what do I know?

Snow
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Dec 13th, 2006, 18:03
Elite Veteran
Join Date: Aug 2005
Location: That Place
Posts: 2,044
Blog Entries: 1
Thanks: 0
Thanked 37 Times in 37 Posts
Re: CSS form labels

I would say it depends on the form. Very complex forms with loads of inputs etc could easily be done with tables and since most users like to tab through forms why not.
__________________

Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Dec 13th, 2006, 23:53
Ryan Fait's Avatar
Elite Veteran
Join Date: May 2006
Location: Las Vegas
Posts: 3,787
Thanks: 0
Thanked 0 Times in 0 Posts
Re: CSS form labels

The tabindex attibute is beautiful, too.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
forms, labels

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Hiding / Showing form fields based on previous form input John Alexander Hopper PHP Forum 1 Mar 10th, 2008 11:30
Button and box labels.What is the best way? Mulith Starting Out 17 Nov 5th, 2007 10:26
Tabs, labels, user group whatsits... pa007 Webforumz Cafe 12 Sep 30th, 2007 03:12
Control Main Timeline Using a Function (Jumping to a different frame using labels) JamesHatter Flash & Multimedia Forum 1 Jun 27th, 2007 21:02
Help Please - Radio Button Labels not showing sandyb Flash & Multimedia Forum 0 Jan 16th, 2006 22:56


All times are GMT. The time now is 15:17.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

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 32 33 34 35 36 37 38 39 40 41 42