|
|
My CSS-based HTML form layout looks awful in Internet Explorer?Dave, I've started a new web site that uses web standards throughout, including CSS layout instead of tables, even for forms. Works great in Mozilla, Firefox, Safari, IE 5 for Mac, etc. Guess what the problem is? Yep, it's Internet Explorer for Windows. The form looks like absolute garbage on IE 5.5 and IE 6 for Windows. Any ideas how I can fix this to use CSS layout for forms, even with IE?
Some variant of "how do I get my pages to look the same on all browsers" is such a common problem that when I teach Web classes or offer workshops on HTML and Cascading Style Sheets, I'll write a mantra for the class on the board when we start: "How a page renders is up to the browser, not the developer!" In a nutshell, what works for one Web browser often doesn't work properly on another, as you're learning. I've looked at your Web site with a variety of browsers, and can see what you're talking about in terms of form elements being unaligned. For example: ![]() click on the image for a full-size representation
Digging into your page, your form elements look like this: <input type="text" id="email" name="email" size="60" value=""/> so I need to move into your CSS sheet to see how the id "email" is defined. It's not, as far as I can see, but the element immediately before the input element on the page is <label for="email">E-mail:</label> and that does have a CSS style definition: textarea, label, input {
display: block;
width: 80%;
float: left;
margin-bottom: 1ex;
}
input[type="submit"] {
width: auto
}
label {
text-align: right;
width: 5em;
padding-right: 20px;
}
Now we're getting somewhere! You're using the label container to detail the width (5em, or em-spaces) so that all elements with labels will force the same width container and therefore cause everything to line up.
I'm betting that the problem is that the IE document object model, the DOM, doesn't allow block-type modifiers like "width" within a label container. Here's how I'd try to fix things: <span class="fixedwidth"> <label for="email">E-mail:</label> </span> <input type="text" id="email" name="email" size="60" value=""/>You'd also need to define the class "fixedwidth" for this to work, obviously. I commonly see misapplied CSS attributes in the a tag, actually, and often wrapping an a href with a span quickly solves any unapplied CSS attribute problems. Oh, one tiny niggle while we're looking at your code: the trailing /> is good XHTML form, but you need a space immediately before the slash for it to be valid. Instead of ... value=""/> it should more correctly be ... value="" />. Otherwise, Elliotte, your The Cafes site looks great and the underlying CSS is certainly most educational to read! Anyway, try the changes and let me know if that fixes the problem in IE!
Related HTML, JavaScript and Web Site Programming articles:
✔ How to Create Predefined Google Image Search Links?
Thanks for the Amazon URL [see Creating Amazon Search Links]. That worked beautifully. In fact, I sent you $5.00 for coffee in thanks....
✔ Can I embed a Facebook search box on my blog site?I've seen your articles about how to add a Twitter or Google search box on a Web page, but I have a tougher...
✔ Can I use CSS for drop shadows on my blog?I want to give my site a bit of a facelift and add some neat graphical elements. One of which is drop shadows....
✔ How can I embed interactive photo panoramas on my site/blog?I read through your blog entry about how to take panoramic photos with iOS 6 and an iPhone 5 and got enthused. I've...
✔ How can I create a Twitter search URL shortcut?I'd like to add a few Twitter search links to my Web site. Is that possible, or does Twitter prohibit this sort of...
Let's stay in touch!
Sign up for my weekly AskDaveTaylor Newsletter and you'll receive even more tech and gadget help
right to your inbox, along with exclusive news and industry updates. It's good stuff. I promise!
Categorized:
HTML, JavaScript and Web Site Programming
(Article 3797,
Written by Dave Taylor)
Tagged: Previous: How do I fix a messed up BIOS on an XP PC? Next: What's the fastest way to sell something on eBay? Reader Comments To Date: 12Dave Taylor said, on December 8, 2004 3:59 PM:
Hmmm.... well, I would say that sometimes a table is a better choice than forcing everything into CSS (I think about "if you have a hammer, everything looks like a nail"). The forms on my Web sites are built around tables for layout... last I checked, the CSS standard didn't deprecate everything in the world of HTML, so I think it's still legal and legit to use tables for this sort of thing, Elliotte. :-) Elliotte Rusty Harold said, on December 9, 2004 1:27 PM:
The Web Accessibility Guidelines at http://www.w3.org/TR/WAI-WEBCONTENT/#gl-table-markup are quite clear that table markup should be reserved for genuine tables, not for layout. I know I could go back to tables; but, damn it, this should be possible. Dan Dean said, on January 24, 2005 7:38 PM:
Here's how I do mine, and it works pretty well. I came across this technique on someone elses site, so I can't take the credit. ( I think it was quirksmode.org?) Anyways, here's the code: /* CSS */
Basically what this does is floats all form labels on the left, but text aligns them right. Then, all of the form elements are floated left, so the scoot over to the edge of the labels. This works because all of the labels are given a predifined width, so everything is nicely aligned. Making the line breaks clear:both is essential in that, since floats don't automatically clear, the next form element is forced to position itself on the next available row of space. Hope this helps. Dave Taylor said, on January 24, 2005 9:16 PM:
That's a very interesting solution, Dan. Thanks for sharing it. Can you also share the URL of the actual Web page that includes this form? Thanks. larry p said, on March 11, 2005 9:57 PM:
You can find a write up of this technique at http://www.quirksmode.org/css/forms.html Three caveats: 1. it won't work in IE 5 (and presumably below) [fine, of course in Opera and Firefox/Mozilla] 2. you must remember *not* to wrap your labels around their associated inputs [which I, at least, was taught to do in HTML 101] 3. In a practical case, where you might have two columns, say a nav column floated to the left and then fluid a main content column, which contains your form elements, in the center of the rest of the page, you need to wrap the form elements inside their own float container (a fieldset would work). If you don't do that, all the rest of the form elements will drop down below the floated navigation bar after the first clearing line break. Noor said, on October 23, 2006 7:27 PM:
I'm not much of a web designer and am horrible with code, but I am a traditional print designer. I'm working on my website in Dreamweaver MX 2004 for OSX. Everything seems to be okay when viewed on a Mac, however when viewed on IE for PC all the txt is alligned center instead of flush left. Any suggestions? Again I apolgoze, I am not much of a coder. Noor said, on October 23, 2006 9:37 PM:
I'm not much of a web designer and am horrible with code, but I am a traditional print designer. I'm working on my website in Dreamweaver MX 2004 for OSX. Everything seems to be okay when viewed on a Mac, however when viewed on IE for PC all the txt is alligned center instead of flush left. Any suggestions? Again I apolgoze, I am not much of a coder. Jessica said, on January 18, 2009 6:21 PM:
i have a similiar problem and my layout that i created for work will work fine in all browsers but the IE.. i am not sure what to do or why it does this.. and I read above what you have commented but is that the coding only for making the forms? Web Designing Gurgaon said, on July 26, 2009 11:34 PM:
I am having trouble in keeping a select and text field in line in IE, though it works fine in Firefox. Any tips that help me tide over this problem are most welcome? Usman Rehman said, on September 5, 2011 5:10 PM:
Dear Dev, don said, on November 28, 2011 2:29 PM:
hello my name is don , and i have a problem with my form showing up as a long list instead of two columns. I used css to create the two columns but when i use it on my website it shows up as a list here is my website (http://www.pittsburghspikes.com/index.php/prospective-players) ... sorry if i am not following the topic but i didnt know where to start my own and if anybody would answer me
I do have a comment, now that you mention it!Check This Out Too... |
Recent Entries
Look for Answers
Recommended
All Our Categories
Apple iPad Help
Articles and Reviews Auctions and Online Shopping Blogs and Blogging Building Web Site Traffic Business and Management Computer and Internet Basics d) None of the Above Facebook Help Google Gmail Help Google Plus Help HTML, JavaScript and Web Site Programming Industry News and Trade Shows iPhone and Cell Phone Help iPod, Sony PSP and MP3 Player Help Kindle Fire Help Mac OS X Help Pay Per Click (PPC) Advertising Pinterest Help Search Engine Optimization (SEO) Shell Script Programming Tech Support Video Help The Writing Business Twitter, LinkedIn and Social Network Help Unix and Linux Help Video Game Tips and Help Windows PC Help Find Me on Google+ ADT on G+ |
Good idea. Putting everything in spans instead of styling the form elements directly allowed me to fix the overly large preview button in Internet Explorer. However, it didn't fix anything else, and it misaligned the textarea and made the form fields start slipping under the menu bar again for small browser widths, even in Mozilla. I tried divs instead of spans. No luck there either. :-(