Sidebars in CSS

Sidebars in CSS are a common UI element in web design, and can be implemented using CSS in a variety of ways. Here’s an example of how to create a simple fixed position sidebar using CSS:

HTML:

				
					<div class="container">
  <div class="sidebar">
    <ul>
      <li><a href="#">Menu Item 1</a></li>
      <li><a href="#">Menu Item 2</a></li>
      <li><a href="#">Menu Item 3</a></li>
      <li><a href="#">Menu Item 4</a></li>
    </ul>
  </div>
  <div class="main-content">
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vitae semper quam. In vel ullamcorper ipsum. Vestibulum vel mauris at nunc tincidunt semper.</p>
  </div>
</div>

				
			

CSS:

				
					.container {
  display: flex;
  flex-wrap: wrap;
}

.sidebar {
  background-color: #f1f1f1;
  width: 200px;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
}	

.main-content {
  flex: 1;
  padding: 20px;
  margin-left: 200px;
}

				
			
Join To Get Our Newsletter
Spread the love