Overflow Scroll CSS Is Not Working in the Div

overflow-y: scroll not working, showing style but cannot be scrolled?

There is no need to scroll.

The browser will only scroll if the content within the div needs to scroll in order to see more items in the ul. To make the scroll bar appear only if it needs to be there, you can use overflow-y: auto.

You implicitly tell the browser to show to the scroll bar even though it's not needed with such little ul elements. Try adding more elements to see the scroll bar work properly.

.list {
margin: auto;
height: 285px;
width: 300px;
overflow-y: auto; /* This changed */
}

<div class="list">
<ul>
<li> hello world </li>
<li> hello jupiter </li>
<li> hello mars </li>
<li> hello world </li>
<li> hello world </li>
<li> hello world </li>
<li> hello world </li>
<li> hello world </li>
<li> hello world </li>
<li> hello world </li>
<li> hello world </li>
<li> hello world </li>
<li> hello jupiter </li>
<li> hello mars </li>
</ul>
</div>

Deleting some of those li elements will cause the scroll bar to shrink until it is not needed anymore.

overflow-y scroll not working for ul nested in div

Remove overflow-y: hidden from the div container element.

Add an explicit height to the ul.

div {
background-color:#FFFFEE;
width: 200px;
height: 100px;
//overflow-y: hidden;
}

ul {
height: 100px;
overflow-y:scroll;
}

Should do the trick.

CSS overflow not working as expected and unable to scroll to bottom of div

The problem is with BelowNavContainer Component.

You've set its height to 100vh, but notice that there is header above it, so the total height of the full page now is :

header Height + 100vh(BelowNavContainer height).

and as you put thier parent component: ProjectContainer height to 100%, overflow: hidden, this will hide the bottom of the DashboardBody' component.

Solution:

to put height of BelowNavContainer as follows:
height: calc(100vh - 100px)

as 100px:is the hieght of your header

you can see this wrking demo

Overflow Scroll css is not working in the div as expected

If you want the vertical scrollbar to apply to just the scrollable content, you can put everything into a container that’s set to the full viewport height, and then use flex to have a second container that’s used for the content to fit the space left after the navbar. Applying overflow: auto to the second container will give it a scrollbar like your illustration.

body {
margin: 0;
padding: 0;
}
.container {
height: 100vh;
display: flex;
flex-direction: column;
}
.nav {
padding: 1rem;
background-color: blue;
}

.content {
padding: 1rem 35%;
overflow: auto;
flex-grow: 1;
font-size: large;
}
<div class="container">
<div class="nav">
<h1>Nav content</h1>
</div>
<div class="content">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

<p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?</p>

<p>At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.</p>
</div>
</div>

Overflow-y auto not working in this case

You must give perfect height to the content element in order for the scroll to work.

height: calc(100vh - 24px - 40px - 40px);

html {

height: 100%;

}

body {

font-family: 'Open Sans';

font-weight: 300;

font-size: 20px;

color: #3d5266;

margin: 12px;

background: lightblue;

}

#container {

max-width: 800px;

position: relative;

overflow: hidden;

max-height: calc(100vh - 24px);

border-radius: 6px;

box-shadow: 0 1px 3px 1px rgba(0,0,0,0.2);

margin: auto;

}

header, footer {

position: absolute;

width: 100%;

height: 40px;

line-height: 40px;

background: #fff;

z-index: 5;

outline: 1px solid rgba(0,0,0,0.1);

padding: 0 8px 0 8px;

}

header {

top: 0;

border-radius: 6px 6px 0 0;

}

footer {

bottom: 0;

border-radius: 0 0 6px 6px;

}

section {

margin: 40px 0;

}

.content {

position: relative;

height: calc(100vh - 24px - 40px - 40px);

overflow-y: auto;

overflow-x: hidden;

background: #fff;

padding: 8px;

}

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

<header>

header text

</header>

<section>

<div class="content">

bla<br>

bla<br>

bla<br>

bla<br>

bla<br>

bla<br>

bla<br>

bla<br>

bla<br>

aaaabla<br>

bla<br>

bla<br>

bla<br>

bla<br>

bla<br>

bla<br>

bla<br>

</div>

</section>

<footer>

footer text

</footer>

</div>

Setting overflow to scroll on fixed div doesn't work

Problem solved.
Using min-height keeps the menu render forever but when used height only scroll works perfectly.

Nested div will not scroll

If you set 100% at your height property from .items class, your <div> tag will expand until all nested items are shown. To enable your scroll , the height of the <div> with class .items must be lower to what it would have if your div expanded to accommodate all nested tags.

Try to set your height property lower than 100% or set in pixels (100px, for instance).



Related Topics



Leave a reply



Submit