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

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay