Creating a Full Height Page with Fixed Sidebar and Scrollable Content Area in CSS

CSSWeb DevelopmentFront End Technology

A full-height page with a fixed sidebar and scrollable content area can be created by setting the height to 100% and applying proper positioning of elements.

The following example illustrates the above.

Example

 Live Demo

<!DOCTYPE html>
<html>
<head>
<style>
.main {
   margin-left: 140px;
   font-size: 200%;
   padding: 0 3%;
}
section {
   height: 400px;
   background-color: tomato;
}
.sidebar {
   height: 100%;
   width: 140px;
   top: 0;
   left: 0;
   position: fixed;
   background-color: darkslategrey;
   padding-top: 20px;
}
.sidebar a {
   display: block;
   padding: 2% 4%;
   text-decoration: none;
   color: lightblue;
   font-size: 1.4em;
}
.sidebar a:hover {
   color: mistyrose;
   font-size: 1.8em;
   box-shadow: inset 0 0 15px rgba(0,0,0,0.6)
}
</style>
</head>
<body>
<div class="sidebar">
<a href="#">Option a</a>
<a href="#">Option b</a>
<a href="#">Option c</a>
<a href="#">Option d</a>
<a href="#">Option e</a>
</div>
<div class="main">
<h3>Example</h3>
<article><p>Vivamus non elementum felis. Sed sagittis lectus ligula, maximus interdum eros lacinia non. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculusmus. Maecenas id purus neque. Donec auctor mollis vehicula. Nulla luctus mauris ut gravida
interdum. Aenean vel hendrerit massa, vel feugiat dui. </p>
<img src="https://images.unsplash.com/photo-1611670159228- eff9d9e5b3a1?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=200&ixlib=rb1.2.1&q=80&w=200" />
<p>Phasellus ac felis consectetur lectus varius gravida ac in nunc. Suspendisse ut velit sagittis,
mattis nibh eu, semper massa. Maecenas in ligula fringilla, tristique libero sit amet, convallis ex. Sed condimentum id nulla non dignissim. Vestibulum sollicitudin eros id varius ornare.</p></article>
<section></section>
</div>
</body>
</html>

Output

This will produce the following result −

raja
Published on 13-Mar-2021 12:18:54
Advertisements