Forum Moderators: not2easy

Message Too Old, No Replies

select tag wrapping in IE

         

heisters

12:29 am on Mar 29, 2007 (gmt 0)

10+ Year Member



Hi all,

I'm having a problem getting a CSS form to work. I'm using a pattern that I always use: set a label to fixed-width so the fields line up, then float the labels so that their fields lie next to them. It works fine in FF, but in both IE6 and 7, the select tag wraps to the next line, even though it appears that there's more than enough room for it. The only way I can get it to align correctly is to set the width of the form to something far too big, like 500px.

Here's the code, stripped down to the essentials. It's completely valid, works in FF2 and doesn't in IE6. Any ideas?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
<style type="text/css">
* {
font-family: Arial,Helvetica,sans-serif;
font-size: 13px;
}
#map form {
width: 280px;
float: left;
border: 1px dashed red;
}
#map div.input_set {
border: 1px dashed blue;
clear: both;
float: left;
}
#map select {
width: 121px;
}
#map label {
font-weight: bold;
display: block;
width: 85px;
text-align: right;
float: left;
}
</style>
</head>
<body>
<div id="map">
<form action="/search" method="get">
<h3>SEARCH NEARBY</h3>
<div class="input_set">
<label for="q">Search For:</label><input type="text" size='20' name="q" id="q" value="" />
</div>
<div class="input_set">
<label for="proxDistance">Within:</label><select name="proxDistance" id="proxDistance">
<option value="">(any)</option>
<option selected="selected" value="3218.688">2.0 miles</option>
</select>
<input type="submit" name="go" value="GO" />
</div>
</form>
</div>
</body>
</html>

simonuk

3:23 pm on Mar 29, 2007 (gmt 0)

10+ Year Member



There are a number of ways of fixing it. The quickest is removing the float:left on the input_set (You could get rid of clear:both as well).

heisters

6:45 pm on Mar 29, 2007 (gmt 0)

10+ Year Member



wow, do I feel dense. Those are just from another implementation where they were necessary, but it's fine to take them out here.

So any idea *why* it renders differently in IE than FF?

simonuk

1:35 pm on Mar 30, 2007 (gmt 0)

10+ Year Member



I think in this case it's because the button is also on the same line and IE can give form buttons lots of extra padding.

If this fix does cause you problems you could try this...

Create a button class:

<style>
.button{margin:0;padding:0 .25em;width:auto;overflow:visible;}
</style>

<!--[if IE]>
<style>.button{width:1;}</style>
<![endif]-->

heisters

10:31 pm on Mar 31, 2007 (gmt 0)

10+ Year Member



cool, thanks much for the tips, simonuk