DEV Community

Cover image for Scrollable Content With Sticky Sidebar Using CSS
Gaurav Adhikari
Gaurav Adhikari

Posted on • Edited on

2 2

Scrollable Content With Sticky Sidebar Using CSS

In this post, we are going to quickly see how can we create a page with Scrollable Content and Sticky/Fixed Sidebar.

We will create three div, one parent div i.e. Container and rest two are for Content and Sidebar.

<div class='container'>
   <div class='content'>
   </div>
   <div class='sidebar'></div>
</div>
Enter fullscreen mode Exit fullscreen mode

We will use display as Grid to achieve our task, the CSS goes below

.container {
display: grid;
gap: 0 1rem;
grid:
"header side" auto
"inside side" auto
"content side" auto
"footer side" auto / auto 16rem;
margin: 0 auto;
max-width: 50rem;
padding: 1rem;
position: relative;
}
.content {
grid-area: content;
}
.sidebar {
grid-area: side;
margin-top: 1.5rem;
position: fixed;
right: calc(50% - 28.5rem);
top: 0;
width: 15rem;
}
Enter fullscreen mode Exit fullscreen mode

That's it, just add your required HTML into content and side div respectively.

Happy Coding, Thanks!

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay