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

  • SEARCH
  • Home
  • 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 6334641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:41:59+00:00 2026-05-24T18:41:59+00:00

So, I need to have a header that’s always displayed at the top of

  • 0

So, I need to have a header that’s always displayed at the top of the viewport, even when the user scrolls down. That bit is fairly easy, using something like this:

body {
    padding-top: 100px; /* height of the header */
}

#header {
    position: fixed;
    top: 0;
    left: 50%;
    margin-left: -500px; /* Half the width of the header */
    width: 1000px;
    height: 100px;
}

However, now my problem is that I don’t always know how tall the header will be, because the client wants a top banner ad to also follow along, but that might not always be there.

So, sometimes the header might look like this:

<div id="header">
    <img src="#" class="top_banner" />
    <div id="headerbar">
        <h1>Site logo</h1>
    </div>
</div>

And sometimes it might look like this:

<div id="header">
    <div id="headerbar">
        <h1>Site logo</h1>
    </div>
</div>

The good news is that the banner ad will always have the same dimensions. So basically #header could be 100px without the banner, and 250px if the banner is there.

My question to you is: is there a nice CSS ways to solve this? If not, how could I solve it using Javascript?

  • 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-05-24T18:42:01+00:00Added an answer on May 24, 2026 at 6:42 pm
    $(document).ready(function(){
     $('body').css('padding-top', $('#header').height() + 'px');
    });
    

    this can help you

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with a header that user regular tr tags (not th).
I have IndexController. I need to set raw header in indexAction. I try to
I have several jsf pages. I need to add dynamic breadcrumbs to the header.xhtml.
I have need to pack four signed bytes into 32-bit integral type. this is
I have need for a function pointer that takes two arguments and returns a
I need to have custom checkboxes which wasn't that tricky. I made checkbox_selector to
I need to have a list of links generated by JSF and displayed in
I have a header that is larger than the width of the page so
I have used t:commanSortHeader in my table and i need that table to have
.Hi, I have a nib file that contains an header that will be used

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.