I am working on a project in which one of the sections is filled with elements by requesting data from the database, therefore the number of elements in it is extremely variable.
The tricky part is that our design is based on the idea of not having to scroll on the page, but instead scroll on the sections if it is necessary. I thought using overflow
on the sections would suffice but it does not give me the intended result.
I tried all of the variations of the overflow
property, scroll
displays a scroll bar but it seems to be frozen.
How can I make section-one
scrollable within itself, without making the rest of the page scrollable?
I created a code pen with a dummy version to demonstrate the problem: http://codepen.io/leofontes/pen/aNaBox
body {
overflow: hidden;
}
main {
margin: 0;
width: 100%;
height: 100%;
}
.section-one {
background-color: #FF0000;
float: left;
min-height: 1400px;
overflow: visible;
width: 15%;
}
.section-two {
background-color: #00FF00;
float: left;
min-height: 1400px;
width: 70%;
}
.section-three {
background-color: #0000FF;
min-height: 1400px;
float: left;
width: 15%;
}
<main>
<section class="section-one">
<p>this is section one</p>
<p>this is section one</p>
<p>this is section one</p>
<p>this is section one</p>
<p>this is section one</p>
<p>this is section one</p>
<p>this is section one</p>
<p>this is section one</p>
<p>this is section one</p>
<p>this is section one</p>
<p>this is section one</p>
<p>this is section one</p>
<p>this is section one</p>
<p>this is section one</p>
<p>this is section one</p>
<p>this is section one</p>
<p>this is section one</p>
<p>this is section one</p>
<p>this is section one</p>
<p>this is section one</p>
<p>this is section one</p>
</section>
<section class="section-two">
<p>this is section two</p>
</section>
<section class="section-three">
<p>this is section three</p>
</section>
</main>
Thank you
Make these adjustments to your CSS:
html {
height: 100%; /* note #1 */
}
body {
height: 100%; /* note #1 */
margin: 0; /* note #2 */
overflow: hidden;
}
main {
margin: 0;
height: 100%;
}
.section-one {
background-color: #FF0000;
float: left;
overflow-y: auto; /* new */
width: 15%;
height: 100%; /* note #3 */
}
.section-two {
background-color: #00FF00;
float: left;
min-height: 1400px;
width: 70%;
}
.section-three {
background-color: #0000FF;
min-height: 1400px;
float: left;
width: 15%;
}
<main>
<section class="section-one">
<p>this is section one</p>
<p>this is section one</p>
<p>this is section one</p>
<p>this is section one</p>
<p>this is section one</p>
<p>this is section one</p>
<p>this is section one</p>
<p>this is section one</p>
<p>this is section one</p>
<p>this is section one</p>
<p>this is section one</p>
<p>this is section one</p>
<p>this is section one</p>
<p>this is section one</p>
<p>this is section one</p>
<p>this is section one</p>
<p>this is section one</p>
<p>this is section one</p>
<p>this is section one</p>
<p>this is section one</p>
<p>this is section one</p>
</section>
<section class="section-two">
<p>this is section two</p>
</section>
<section class="section-three">
<p>this is section three</p>
</section>
</main>
Revised Codepen
Notes:
body
element.height
to the element causes the overflow
to work.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With