Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9158725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:19:02+00:00 2026-06-17T13:19:02+00:00

I made a lengthy page that I’m testing on my computer. Since it’s so

  • 0

I made a lengthy page that I’m testing on my computer. Since it’s so long, I added a table of contents to the top. Under the table of contents are some links that, when clicked, take you to a specific section of the page. Here’s an example of the markup I used:

<h4>Table of Contents</h4>
<ul>
    <li><a href="#gotolink">Link</a></li>  
</ul>
<h3><a name="gotolink">Link</a></h3>
    <p>some stuff here</p>

It works fine. The problem is that I also have a fixed header, as in you always see the header no matter where you are on the page, and when I click a link under the table of contents it takes me to that section of the page but the header ends up covering the <h3> stuff. I want to make it so that when you click a link it takes you to that section of the page, but the section will be in the middle of your screen, not the top, so the header won’t cover anything.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:19:03+00:00Added an answer on June 17, 2026 at 1:19 pm

    Solution

    You can do this by setting position: relative; on the target <a> element; just give the header a set height, and set top: -[header height] on the <a>.

    Demonstration

    Here’s a JSFiddle. Click the Link at the top of the long page (please excuse the vast amount of Lorum Ipsum). The page will jump down to the red title.

    CSS

    body {
        margin-top: 20px;    /* Same height as header */
    }
    
    #header {
        position: fixed;
        background: black;
        color: white;
        height: 20px;
        line-height: 20px;
        width: 100%;
        top: 0;
    }
    
    h3 a {
        position: relative;
        top: -20px;    /* Negative header height */
    
        /* Don't select anchor */
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        -o-user-select: none;
        user-select: none;
    }
    

    Caveats

    • The header must have an explicit height so offsets can be set correctly.
    • As the <a> is offset from the containing element (<h3> in this case), user selection is disabled with user-select: none. This means that any text in the <a> isn’t selectable. This is why I didn’t wrap the <h3>‘s text in it in the JSFiddle demo.
    • This won’t place the target title in the middle of the screen, however it will position it underneath the header.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made a function in jQuery that will get some data form page and
I have made a quick ajax driven page for pasting some text and running
Suppose I have a polygon ( a lengthy rectangle ) made up of several
Made a custom obj called Item with some string fields and one float. .h
I made an iphone app to capture image from camera and to set that
I made a Web service in which I have a function to count some
I made an application that passes trough an XML file and extracts the entries
i made an .xib file and added my buttons and labels. Then I created
I made a web app that loads images using jquery, ajax and json. I
So, I have a page that loads and through jquery.get makes several requests to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.