Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overflow-x: hidden also hides vertical content too

Tags:

html

css

overflow

I have a DIV measuring 400px wide, containing two DIVs side-by-side, each with width of 400px and height of 600px. The width of both DIVs is fixed, however the height can vary. I'd like to hide the second DIV and show the first completely, with no scrolling inside the DIV.

My solution, I thought, was to hide the overflow-x. This seems to also hide the y overflow too.

Here's my code:

#schools-sub-nav {  }  #schools-container {    width: 400px; /* Set the width of the visible portion of content here */    background-color: fuchsia;    position: relative;    overflow-x: hidden;  }  #schools-list {    width: 400px; /* Set the width of the visible portion of content here */    height: 600px; /* Delete the height, let the content define the height */    background-color: purple;    position: absolute;    top: 0;    left: 0;  }  #boards-list {    width: 400px; /* Set the width of the visible portion of content here */    height: 600px; /* Delete the height, let the content define the height */    background-color: green;    position: absolute;    top: 0;    left: 400px;  }
<div id="schools-sub-nav"> <a href="#schools-list">Schools List</a> // <a href="#boards-list">Boards List</a> </div>  <div id="schools-container">      <div id="schools-list"> One </div>      <div id="boards-list"> Two </div>  </div>

I expect #schools-list to be visible, but for some reason overflow-x: hidden in #schools-container hides it.

like image 257
Olly F Avatar asked May 03 '12 17:05

Olly F


People also ask

What does overflow-X hidden mean?

The overflow-x CSS property sets what shows when content overflows a block-level element's left and right edges. This may be nothing, a scroll bar, or the overflow content.

What does overflow-X hidden do in CSS?

The overflow-x property in CSS specifies whether to add a scroll bar, clip the content or display overflow content of a block-level element, when it overflows at the left and right edges. In other words, this property helps us to display the content which is overflowing from the page horizontally.

What is the opposite of overflow hidden?

hidden. The opposite of the default visible is hidden. This literally hides any content that extends beyond the box. This is particularly useful in use with dynamic content and the possibility of an overflow causing serious layout problems.

Does overflow hidden prevent scrolling?

To prevent scrolling with this property, just apply the rule overflow: hidden to the body (for the entire page) or a container element. This hides all content beyond the element's border.


1 Answers

The way you made the two divs (with an absolute position) void the overflow rule!

You need to change the position type (to normal/not absolute) and I suggest using floats, finally, the container div that you want to apply the overflow, needs to have a way to fit it, like placing a div at the end with clear: both (in the case of using floats).

EDIT: I just tried it and you can hide the second div by following the upper suggestion and adding another surrounding div inside with a very large width and change the overflow-x to overflow for the main container div.

Like this:

<div id="schools-container">   <div id="schools-container-inside">      <div id="schools-list"> One </div>      <div id="boards-list"> Two </div>   </div> </div> 

And then the CSS (I commented the original not used CSS and added the new div class at the end):

#schools-container {     width: 400px; /* Set the width of the visible portion of content here */     background-color: fuchsia;     position: relative;     /*overflow-x: hidden;*/     overflow: hidden; } #schools-list {     width: 400px; /* Set the width of the visible portion of content here */     height: 600px; /* Delete the height, let the content define the height */     background-color: purple;     /*     position: absolute;     top: 0;     left: 0;     */     float: left; } #boards-list {     width: 400px; /* Set the width of the visible portion of content here */     height: 600px; /* Delete the height, let the content define the height */     background-color: green;     /*     position: absolute;     top: 0;     left: 400px;     */     float: left; } #schools-container-inside {     width: 10000px;     overflow: hidden; } 

JsFiddle here: http://jsfiddle.net/MbMAc/

like image 59
jackJoe Avatar answered Sep 18 '22 23:09

jackJoe