Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What purpose does overflow: hidden; serve?

Tags:

css

I have a web page with a header area in the middle. Elements are then part of the header. Can someone explain what overflow: hidden; does here. I don't understand why I need it or what it does.

#hdr_mdl {
    margin: 0 auto;
    overflow: hidden;
    width: 980px;
    z-index: 10;
    height: 50px; 
}
like image 348
Samantha J T Star Avatar asked Oct 02 '11 16:10

Samantha J T Star


2 Answers

overflow:hidden prevents scrollbars from showing up, even when they're necessary.

Explanation of your CSS:

  • margin: 0 auto horizontally aligns the element at the center
  • overflow:hidden prevents scrollbars from appearing
  • width:980px sets the width of the element to be 980px.
  • z-index:10 causes the element to stay on top of elements without a defined z-index, *or- elements with a z-index below 10, or elements with a z-index of 10, but defined in before the current element
  • heigh:50px - a height of 50px.
like image 79
Rob W Avatar answered Oct 23 '22 04:10

Rob W


When overflow: hidden is added to the container element, it hides its children that don’t fit in the container.
Example:

.overflowhidden {
 background: green;
 width: 10rem;
 height: 10rem;
 overflow: hidden;
}
<div class="overflowhidden">
 This container has the style overflow:hidden. Text that does not fit becomes hidden. This is a very long sentence of text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text even more text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text this is the end of the sentence.
</div>
like image 24
UserName Name Avatar answered Oct 23 '22 04:10

UserName Name