Yogesh Chauhan's Blog

How to create a sticky menu pin using CSS?

in CSS on February 5, 2021

Let’s add the simple HTML first. I have created links in div tag but we can have that in ul list or any other tag.

Aslo, there are additional paragraphs with ids so that it can be linked with the menu links.

Now, we are just gonna make the use of CSS position property.

The position property specifies the type of positioning method used for an element (static, relative, absolute, fixed, or sticky).

We can use the value fixed so that the menu container can be positioned relative to the browser window.

The ‘top: 20%‘, ‘left: 0‘ and ‘position:fixed‘ will set the position of the div container. So, 20% from the top of the window, and 0 from the left.

You can choose any values like ‘top: 50%‘, ‘left: 0‘ or ‘top: 50%‘, ‘right: 0‘ or ‘bottom: 0‘, ‘left: 0‘ etc. ‘bottom:0‘ will place the container wt the bottom of the window.

Here is the CSS code:

Checkout the end result on JSFiddle


Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 How to add Read More Read Less Button using JavaScript? #3 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #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

#Jan 17 4 advanced ways to search Colleague #Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface #Jan 14 How to display a student’s individual transcript in Colleague? #Jan 11 How to install PuTTY on a MacOS?
You might also like these
Always add associated labels to your Form elementsUI/UXinclude, include_once, require, require_once in PHPPHPasync function in JavaScriptJavaScriptSanitize inputs using built-in WordPress functionsWordPressKilling A Project Part 1: What criteria should be used to cancel/kill a project?MiscellaneousContent Blocks in SCSS (Sass)SCSSHTML Copyright SymbolHTMLThe substr() method in JavaScript and how it’s different from substring()JavaScriptSolution for Xcode 11 Command PhaseScriptExecution failed with a nonzero exit code errorMiscellaneousHow to create a Star Ratings using CSS?CSSPHP Variables ScopePHPSQL Right JoinSQL/MySQL