0

I have a blog of code written such as this:

<div class="box">
   <div class="statusbox">
      <div class="cleft">some stuff</div>
      <div class="cright">some more stuff</div>
   </div>
</div>

and this is the CSS code for it:

.box{padding:10px; border: 1px black solid;width: inherit;}
.statusbox{border-bottom: 2px #736f6e solid;}
.cleft{float:left;width:84%;vertical-align:middle;min-height:50px;margin-right:10px;padding-top: 5px;}
.cright{float:right;width:15%;text-align:right;vertical-align:middle;min-height:50px;padding-top: 5px;}

The issue I'm having is that the structure is not obeyed in terms of the CSS layout. Whilst cleft and cright show correctly, they are not being embedded within statusbox and box. box and statusbox just clump up together, just above the "some stuff".

Here's an image of what I'm currently getting: alt text

1 Answer 1

6

Add overflow: hidden to statusBox

Floated elements do not contribute to the height of the parent. Since both of your elements are floated, then the parent has no height. Adding overflow: hidden changes that.

Sign up to request clarification or add additional context in comments.

3 Comments

Peter Paul Koch (aka PPK) has a nice article about clear floats with overflow: PPK: CSS clearing floats
I suggest using overflow:auto rather than hidden. It's the usual way of giving parent the size of their child elements consumed space.(still +1 from me)
I generally use hidden to avoid accidental scrollbars.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.