473,660 Members | 2,459 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

2-column layout for form without tables

jhardman
3,406 Recognized Expert Specialist
People keep saying this is possible, but I'm not sure I see it. If I had used a table it would have been done a day ago, but without the table the labels and inputs don't line up. Everything I have tried will line up the inputs at some window sizes, but if I resize the window the next input pops over the the right, or goes up a line. Where is the alleged advantage of using strict css positioning?

Here's my form:
Expand|Select|Wrap|Line Numbers
  1. <html><head><title>Scholarship form</title>
  2. <style>
  3.  
  4. label {
  5. width:30%;
  6. float:left;
  7. text-align:right;
  8. margin-right: 5px;
  9. }
  10.  
  11. input, textarea {
  12. float: none;
  13. display: inline;
  14. }
  15.  
  16. </style>
  17. </head>
  18. <body>
  19. <h1>Scholarship form</h1>
  20. <form>
  21. <label for="applName">Name:</label><input type="text"
  22. name="applName" ><br>
  23. <label for="applAddress">Address:</label><textarea
  24. name="applAddress" rows="2" cols="30"></textarea><br>
  25. <label for="applPhone">Phone:</label><input 
  26.  
  27. type="text" name="applPhone"><br>
  28. <label for="applEmail">Email:</label><input 
  29. type="text" name="applEmail"><br>
  30. <label for="canPay">Can you attend this conference 
  31. without the scholarship?</label><input type="text" 
  32. name="canPay" size="4"><br>
  33. <label for="acceptPartial">Can you attend with a 
  34. partial scholarship?</label><input type="text" 
  35. name="acceptPartial" size="4"><br>
  36. <label for="howWillBenefit">How will attending this 
  37. conference help you?
  38. </label><textarea name="howWillBenefit" cols="35" 
  39. rows="4"></textarea><br>
  40. <input type="submit" name="submit" value="Submit 
  41. Scholarship Application">
  42. </form>
  43. </body></html>
Jared
Jan 23 '12 #1
9 4900
danp129
323 Recognized Expert Contributor
Is this more like what you're wanting?
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3.     <title>Scholarship form</title>
  4.     <style type="text/css">
  5.         label
  6.         {
  7.             clear: left;
  8.             float: left;
  9.             width: 30%;
  10.             text-align: right;
  11.             margin-right: 5px;
  12.         }
  13.  
  14.         input, textarea
  15.         {
  16.             float: left;
  17.             clear: right;
  18.             display: inline;
  19.         }
  20.     </style>
  21. </head>
  22. <body>
  23.     <h1>
  24.         Scholarship form</h1>
  25.     <form>
  26.     <label for="applName">
  27.         Name:</label><input type="text" name="applName">
  28.     <label for="applAddress">
  29.         Address:</label><textarea name="applAddress" rows="2" cols="30"></textarea>
  30.     <label for="applPhone">
  31.         Phone:</label><input type="text" name="applPhone">
  32.     <label for="applEmail">
  33.         Email:</label><input type="text" name="applEmail">
  34.     <label for="canPay">
  35.         Can you attend this conference without the scholarship?</label><input type="text"
  36.             name="canPay" size="4">
  37.     <label for="acceptPartial">
  38.         Can you attend with a partial scholarship?</label><input type="text" name="acceptPartial"
  39.             size="4">
  40.     <label for="howWillBenefit">
  41.         How will attending this conference help you?
  42.     </label>
  43.     <textarea name="howWillBenefit" cols="35" rows="4"></textarea>
  44.     <label>
  45.         &nbsp;</label>
  46.     <input id="submit" type="submit" name="submit" value="Submit 
  47.     Scholarship Application">
  48.     </form>
  49. </body>
  50. </html>
Jan 24 '12 #2
jhardman
3,406 Recognized Expert Specialist
nope, didn't help. Notice the input where I have typed in the word "this" in the picture.


this is the input for the question "Can you attend with a partial scholarship?" which is a properly formatted form label. The problem is more pronounced in internet explorer (on the left) but is still there in ff on the right. Depending on screen resolution the input does not line up with the label and this would be trivial to fix with a table.

Jared
Jan 25 '12 #3
lgm001
9 New Member
can I make a suggestion here? I prefer not to use floats, because this usually results in complete strangeness. For forms I have been using the following format these day...
Expand|Select|Wrap|Line Numbers
  1. <fieldset>
  2. <legend>My Formname or section name</legend>
  3.  
  4. <div>
  5. <label for="controlname">Hello</label>
  6. <input type="text" id="controlname" />
  7.  
  8. <label for="controlname2">Hello</label>
  9. <input type="text" id="controlname2" />
  10.  
  11. </div>
  12.  
  13. <div>
  14. <label for="controlname3">Hello</label>
  15. <input type="text" id="controlname3" />
  16.  
  17. <label for="controlname4">Hello</label>
  18. <input type="text" id="controlname4" />
  19.  
  20. </div>
  21. </fieldset>
with this structure, you can use the following CSS
Expand|Select|Wrap|Line Numbers
  1. fieldset { border: ...; specify a width here etc }
  2. fieldset.div {width: 1/2 the width you specified above; white-space: nowrap; display: inline-block;}
  3. label[for] { width: 120px; display: inline-block;  }
  4. input[type="text"] { width: 200px; }
  5. textarea { width: 198px; }
perfect placement... :)
Also, you can do some really clever positioning if you need to all relative to the label and textbox. You may want to also look into things like adjacent selectors.
I usually add a span inside my label, this can then be absolutely positioned, and then be used with jQuery for various tooltip effects.
Jan 25 '12 #4
danp129
323 Recognized Expert Contributor
Did you copy the entire code? Here's what it looks like on FF9 and IE9.
Attached Images
File Type: jpg csstest.jpg (68.0 KB, 594 views)
Jan 25 '12 #5
jhardman
3,406 Recognized Expert Specialist
Dan, it was totally broken in my IE9, copied exactly from your post.


Jared
Jan 25 '12 #6
drhowarddrfine
7,435 Recognized Expert Expert
You will never get IE to attempt to perform like the other far more modern browsers without a doctype. Put this on your first line:
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html>
Jan 25 '12 #7
danp129
323 Recognized Expert Contributor
Add the doctype like drhowarddrfine said, IE is probably using quirks mode.
Jan 25 '12 #8
danp129
323 Recognized Expert Contributor
lgm001,
Your rule "fieldset.d iv" doesn't do anything, it should be called "fieldset div" to select div elements below a fieldset element. When I make that change it breaks your intended layout.
Jan 25 '12 #9
lgm001
9 New Member
Sorry ... typo.

I stand corrected.
Jan 26 '12 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

6
17062
by: Matthew Wells | last post by:
I am trying to load a form (load Me) without the form becoming visible. If I try me.hide or me.visible = false, they load the form and the form blinks before becoming invisible. Is there a way to load the form without it becoming visible at all until I say me.visible = true? Thanks. Matthew Wells MWells@NumberCruncher.com
54
7210
by: Max Quordlepleen | last post by:
Apologies for the crossposting, I wasn't sure which of these groups to ask this in. I have been lurking in these groups for a week or so, trying to glean what I need to design a simple, clean set of pages that get the w3c tick for XHTML 1.0 Strict, and CSS2. So far, I have succeeded, thanks to the great information in these groups. Now, however, I'm having trouble. A few days ago, I read a thread that dealt with this issue of...
16
3022
by: Jeremy Clulow | last post by:
One disadvantage of designing with CSS and without tables appears to be that selecting specific block of text from a web page to copy and paste, or in order for it to be read by a text-to-speech programme is very difficult. My own website www.webswonder.co.uk is an example. Does anyone have any suggestions as to how to overcome this please? Thanks, Jeremy
8
3087
by: kaeli | last post by:
I have had a little free time lately to revisit a problem I have with the 3 column layout plus a header and footer. See this example: http://glish.com/css/7.asp There is a header and 3 columns. Pretend there's a footer at the bottom, too. :) Here are the issues I have been unable to solve without tables _somewhere_
24
2433
by: Daphne Tregear | last post by:
Is anyone able to improve on this solution, and enable me to do without tables completely? http://www.cs.man.ac.uk/~daf/i-p-c-s.org/faq/gallery_old.php uses a table to lay out the thumbnails and their captions. This a) uses a table, b) wastes space when the window is large and c) overlaps the RHS div when the window is small. I use the same approach for
9
2145
by: effendi | last post by:
Is is possible for me to place to images side by side one -one right align and another left align on the same horizontal plane using CSS without tables? Thanks for any suggestion/advice.
14
10127
by: Abhi | last post by:
FYI: This message is for the benefit of MS Access Community. I found that this prblem has been encounterd by many but there is hardly any place where a complete solution is posted. So I thought I should give back to the community by posting our findings. Thanks you all for all your help till now by posting problems and their solutions. ~Abhijit
7
1381
by: lotusny78 | last post by:
Hi all, I'm trying to lay out 3 text boxes with associated labels horizontally, as in the following pseudocode: <form> TITLE label1 label2 label3 edit1 edit2 edit3
5
4815
by: Markus Ernst | last post by:
Hello This is a test example: http://www.markusernst.ch/anthracite/ http://www.markusernst.ch/anthracite/living_divani.html After googling and experimenting for several hours, I ended up doing this demo with tables. The main problems are the vertical centering of the info area, and of the text inside the squares.
3
2251
by: emajka21 | last post by:
Hello, and thank you in advance for trying to help me. I am trying to create an access 2000 form without using the wizard. It just doesn't seem like I can the level of complexity I want out of the wizard so I want to hand code the form. If this was any other language accessing an access form I know how to do it but I am not sure how to access the tables WITHIN the access database itself. Here is what I would like the form to do. On Load:...
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8341
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8630
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4176
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4342
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2759
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.