Forum Moderators: not2easy

Message Too Old, No Replies

Layout breaks because of form option tags

         

SilverLining

3:39 pm on Mar 14, 2007 (gmt 0)

10+ Year Member



Very strange...

I have a three column layout and making use of <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">.

In the left nav i have two individual forms, each with a maximum width set to the width of the nav bar (Left float). The form tags break the layout and cause the content (middle) div to fall below it. This displays as expected in IE, but breaks in Firefox2. I have tested it to extent where I know the <option></option> tag is the cause of the width/div expanding.

When I restrict the option tag to a (narrow) width i.e.


.search form select option {width: 100px;}

I can see the options deminishing in width, but the layout still breaks.

Any ideas? Is the above clear or do I need to post some code?

Fotiman

4:08 pm on Mar 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It would probably help if you posted some code. But somethings to consider:

1. You really should be styling the <select> instead of the <option>.
2. Setting a width on the select/option could cause some values to become unreadable. For example, the text might not fit in the allocated width and single row select boxes don't provide any way to scroll.
3. Perhaps you should try setting the width on your form container (not the <form> element... you should avoid applying presentational styles to that), and set the overflow style to "hidden" or "scroll"
4. You might want to read the thread: "Why most of us should NOT use XHTML" [webmasterworld.com]

SilverLining

5:15 pm on Mar 14, 2007 (gmt 0)

10+ Year Member



Thanks for your reply and advice.

Here is an example of what I am talking about:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xml:lang="en">
<head>
<style>
html {height: 100%;}
.clear {line-height: 0px; font-size: 0px; clear: both; height: 0px; }
#page {width: 1049px; text-align: left; margin-left: auto; margin-right: auto; border: 1px solid red;}
#page #template {width: 929px; height: 100%; display: table; border: 1px solid blue;}
#page #template #header {width: 929px; height: 147px; border: 1px solid green;}
#page #template #nav {width: 168px; height: 100%; display: table; margin-right: 25px; border: 1px solid orange; float: left;}
#page #template #container {width: 699px; float: left;}
#page #template #container #content {width: 595px; float: left;}
#page #template #container #nav2 {width: 104px; height: 500px; background-color: #dedede; float: right;}
</style>
</head>
<body>
<div id="page">
<div id="template">
<div id="header"></div>
<div id="nav">
<form>
<select><option></option></select>
</form>
<div class="clear"></div>
</div>
<div id="container">
<div id="content">
Content
</div>
<div id="nav2">
nav2
</div>
</div>
</div><!-- /template -->
</div><!-- /page -->
</body>
</html>

If you remove <option></option> the layout seems to work in both IE6 and FF2. In the actual code I also have

<?xml version="1.0" encoding="iso-8859-1"?>
right at the top of the page, but in the example this moves the layout to the left.

height: 100% was added to force the nav bar to 100%, but this does not work in Safari.

I tried setting a width on the form container, but that did not work. At the moment, I don't really have an option, but to try to get this working as XHTML.

SilverLining

5:30 pm on Mar 14, 2007 (gmt 0)

10+ Year Member




/* Added */
- div class="clear" can be removed, without any effect.
- container div previously floated right, but now (as above) floated left and margin-right: 25px; added to #page #template #nav div for correct layout.

Fotiman

6:30 pm on Mar 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The first thing I notice is that your page is not valid. Invalid XHTML can lead to bad things (hence my original post of why most of us should not use XHTML). Also, if you include the xml declaration, I *believe* this causes other problems... for example, IE might go into quirks mode, which may be why it looks as you would expect it to in IE. Your style is missing a type attribute. Your form is missing an action attribute. Your head is missing a title element.

It does seem odd that adding the select/option is causing this problem. It looks like it's not able to calculate the height properly. I poked around for a bit, but I wasn't able to come up with a solution. Sorry. I guess my suggestion would be to try using an existing method for creating the three columns.

Fotiman

6:34 pm on Mar 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Just noticed something...

Your #nav is floated left. You're also trying to specify the height as 100%. However, it can only determine the height if it is explicitly set on it's parent. But floating the element takes it out of the flow, it can't calculate 100%.

Fotiman

6:41 pm on Mar 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You might try using something like the Yahoo UI Library [developer.yahoo.com]'s Grids [developer.yahoo.com] style.

SilverLining

12:05 pm on Mar 15, 2007 (gmt 0)

10+ Year Member



Thanks Fotiman. Your comments re my example code not being valid are true, however my actual code does contain all the missing elements you mentioned.

I have placed the nav and content divs inside a container which fixes the layout. Too far down to change the layout completely, but thanks for the links you posted, one of which (you wouldn't believe) I have read once before: "Why most of us should NOT use XHTML". Time to read it again!