How to fix header even though the page scrolls?

How to Fix Header at the Top on Scroll | CSS Fixed Positioning Tutorial

Fixing header at the top even though the page scrolls

We might have come across few websites were we notice that the header is fixed even though the page is scrolled. One of the familiar site which uses that is Quora http://www.quora.com.

I tried the simliar mockup of quora feed design using html & css.

Implementing Fixed Positioning

To fix the header at top, CSS positioning property is used as:

position: fixed;

Fixed positioning is relative to the containing viewport of the page. No matter, the page is scrolled element will be positioned at the same position.

header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    min-height: 50px;
    border-top: 2px solid #b92b27;
    border-bottom: 2px solid #ddd;
}
            

Github link: Github_page

Mockup Image:

Quora Mockup Output
Visual mockup of the fixed header design.

Comments

Popular posts from this blog

The Ultimate Guide to AI/ML Hosting and Choosing the Best Platform

Best AI Tools for Women in 2025

Why Visakhapatnam is a Data Center hub: Guide to Datacenter Site Evaluation