Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No padding when using overflow: auto

I can't get padding-bottom to work when I use overflow-y: auto on a box.

HTML:

<div id="container">     <div id="some_info"></div> </div> 

CSS:

#container {     padding: 3em;     overflow-x: hidden;     overflow-y: auto;     width: 300px;     height: 300px;     background: red; }  #some_info {     height: 900px;     background: #000; } 

Fiddle.

EDIT: I use Firefox

like image 312
Philip Avatar asked Nov 20 '12 11:11

Philip


People also ask

Why does overflow hidden not work?

It is because you are using position absolute. You cannot use position absolute with overflow hidden, because position absolute moves the targeted element out of context with the document structure.

How do I get rid of scroll padding?

You can apply scrollbar-width: none to the container div. This will hide the scrollbar altogether.

Why overflow is not working in CSS?

One of the most common causes of overflow is fixed-width elements. Generally speaking, don't fix the width of any element that should work at multiple viewport sizes.

How do I fix the overflow in CSS?

overflow: scroll Setting the value to scroll , the overflow is clipped and a scrollbar is added to scroll inside the box. Note that this will add a scrollbar both horizontally and vertically (even if you do not need it): You can use the overflow property when you want to have better control of the layout.


2 Answers

One more solution without extra DIVs.

#container:after {   content: "";   display: block;   height: 50px;   width: 100%; } 

Working in FF, Chrome, IE8-10.

like image 110
isHristov Avatar answered Nov 10 '22 20:11

isHristov


I'm late to the party, but I thought it was worth adding a different solution that addresses some of the concerns raised above.

I came here because of exactly the kind of situation that @Philip raised in response to Alexandre Lavoie's solution: I have dynamically generated content inside the container, so I can't just apply styling to a specific div name like #some_info.

Happily, there's a simple solution for browsers that support CSS3: instead of applying bottom padding to the container, apply a bottom margin to the last child element inside the container.

#container > :last-child {     margin-bottom: 3em; } 

As long as the last child element in the container div is a block-level element, this should do the trick.

DEMO: http://jsfiddle.net/rwgZu/240/

P.S. If Firefox's failure to scroll to the bottom of the padding is indeed a bug (as suggested by @Kyle), it still hasn't been fixed as of Firefox 47.0. Frustrating! Internet Explorer 11.0.9600.17843 exhibits the same behavior. (Google Chrome, in contrast, shows the bottom padding as expected.)

like image 35
Dan Robinson Avatar answered Nov 10 '22 19:11

Dan Robinson