Yogesh Chauhan's Blog

How to create a sidebar using pure CSS?

in CSS on April 2, 2021

Sidebar can be easily created using a script or script framework but it can be created using pure CSS as well.

I am going to use the same concept as switching themes using pure CSS. We’re going to have a hidden checkbox input HTML element and then based on the :checked selector we can add add or remove the style.

Let’s dive in and add the input element and keep it hidden. Also, let’s add the main section that will have all the contents and a button inside to toggle the sidebar.

Now, let’s add the sidebar content and keep it outside of the main section area by positioning it fixed. We’ll keep the style a bit different for the sidebar close button.

Finally, add the style for the :checked selector.

How to move that sidebar to bottom?

Just change the position of the sidebar like this:

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Aug 15 Is PHP still good for back-end programming? #Aug 10 How to create a multisite network in WordPress? #Aug 3 How to create a circle that follows a cursor using JavaScript and CSS? #Aug 3 How to make a curtain slider using jQuery and CSS? #Aug 2 How to progressively load images and add a blurry placeholder? #Aug 1 How to create a placeholder loader (throbber) using CSS?
You might also like these
How to define variables in SCSS (Sass)?SCSSUnary Operators in JavaScriptJavaScriptAggregate Functions Examples in Postgres for BeginnersPostgresHow to list all PHP variables to debug the script?PHPHow services and dependency injection work in Angular?AngularDifference between :where and :is in CSSCSSFunction Scope in JavaScript for BeginnersJavaScriptHow to create a circle that follows a cursor using JavaScript and CSS?CSSResponsive Masonry Grid using CSS columns PropertyCSSHow states work in React?ReactHow to remove special characters (dash, asterisk etc) from any string in PHP?PHPasync function in JavaScriptJavaScript