tags:

views:

49

answers:

3

Hi,

I have html:

<div class="field-label"><label>Email: </label></div>
<div class="field"><input class="input" ......></div>

and piece of css:

.field-label  { clear:left; float:left; padding:0.5em; width:6em;  }
.field { padding:0.5em; }

And it worked fine. But for some elements I wanted to apply following change: when I add width to .field class layout goes to blazes: element with .field class appears under element with field-label class. Container of whole form is width enough to hold elements with field-label & field class.

Why is it happening, did I miss something in css basics?

Thanks ,Pawel

A: 

You might be better off using spans instead of divs for this layout, as spans are inline elements they might behave better than divs. Also, do you have a live example?

Kyle Sevenoaks
A: 

If the label and the field should appear on one line, you have to have a around the two 's witn an explicit width wide enought to contain the two others.

Edelcom
+1  A: 

Did you take into account that padding, margin etc. is not included in width?

Tgr
dragonfly
Ahhh, I didn't take into account the width of the .field-label : http://yfrog.com/fvstyleqj
dragonfly
Container width should be bigger than field width + field-label width + field-label padding (+possibly field padding; I think floats can overlap that but I'm not sure). Also mixing absolute and relative lengths is not a good idea.
Tgr