Trying to create a box that contains sentences (with spaces) and can have a maximum width of 300px. When the text is too long, it will autowrap without a scroll bar.
EDIT:
Actually, I should have mentioned that I will need to float the box left. I’m putting it in a widget like so:
<div>
<div>left control</div>
<div>text</div>
<div>right control</div>
</div>
It works, except when I try to place a background like so:
.rounded-reason {
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
-khtml-border-radius: 5px;
border-radius: 5px;
background-color:#ffffff;
padding:10px;
border: 2px solid red;
margin-top:7px;
margin-bottom:20px;
}
The background is too small. It works if I don’t float the ‘left control’ and ‘right control’, but I want these to appear at the top of the box, not at the bottom.
It should do that.
The CSS
heightproperty should beautoby default. So, if you don’t explicitly define the height, it will grow in height to fill its contents (provided the contents do not haveposition: absoluteorfloat, which will change this behaviour somewhat).Update
Sounds like you might be experiencing auto collapsing parent with floated children.
You can fix that like so… each one has their own pros and cons.
overflow: hiddento the parent. This will however chop off all overflow.<span style="clear: both;"></span>or similar beneath the floats. This adds an extra unsemantic element.:afterCSS pseudo selector to add the clearing element (not supported without JavaScript, and not supported by IE 6/7 respectively)