0

I want to have 5 divs horizontally next to each other spanning the width and height of the window (each div occupies 20% of the window width). Any content that doesn't fit the div should be hidden. This is how the css looks for two of the divs:

#container1 {
    float:left; 
    width:20%; 
    height:100%;
}
#container1 .scrollBox {
    height:100%; 
    overflow:hidden;
}
#container1 .scrollBox .container {
    position:relative; 
    width:94%; 
    float:left;
}
#container1 .scrollBox .content {
    clear:both;
}
#container1 .scrollBox .content p {
    padding:0 5px; 
    margin:10px 0; 
    color:#fff; 
    font-family:Verdana, Geneva, sans-serif; 
    font-size:13px; 
    line-height:20px;
}

#container2 {
    float:left; 
    width:20%; 
    height:90%;
}
#container2 .scrollBox {
    height:100%; 
    overflow:hidden;
}
#container2 .scrollBox .container {
    position:relative; 
    width:94%; 
    float:left;
}
#container2 .scrollBox .content {
    clear:both;
}
#container2 .scrollBox .content p {
    padding:0 5px; 
    margin:10px 0; 
    color:#fff; 
    font-family:Verdana, Geneva, sans-serif; 
    font-size:13px; 
    line-height:20px;
}

The containers appear next to each other as I want, but the overflow content is not hidden. The height fits the content... Any help?

Thank you very much

3
  • 1
    Do you have html,body { margin:0; height:100%; } in your css? Commented Aug 26, 2011 at 10:29
  • Didn't have for the html. That did the trick. Thank you very much! Commented Aug 26, 2011 at 10:48
  • Nice, I put it as an answer ^^ Commented Aug 26, 2011 at 11:16

2 Answers 2

1

User agents need a reference value to solve percentages. When nothing is specified sometimes the viewport height is used but in most of the case you have to explicit it.

html,body {
    margin:0;
    padding:0;
    height:100%;
}

margin and padding rules override some default styles of user agents.

http://www.w3.org/TR/CSS2/visudet.html#propdef-height

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

Comments

0

Put overflow:hidden inside #container1 {} instead of #container1 .scrollBox {}.

Comments

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.