How can I make content appear beneath a fixed DIV element?












42















My intention is to create a menu at the top of the page which remains at the top of the page even when the user scrolls (like Gmail's recent feature which has the commonly-used buttons scrolling down with the user so that it allows them to perform operations on messages without having to scroll to the top of the page).



I would also like to set the content below said menu to appear below it - at present, it appears behind it.



I am aiming for something like this:



+________________________+
| MENU | <--- Fixed menu - stays at top even when scrolling.
+¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬+
| CONTENT BEGINS |
| HERE |
| |
| |
| |
| |
| |
| |
+¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬+ <--- Bottom of page.


I hope to have the menu at the top which never moves and which stays at the top of the page, even when the user scrolls down. I am also looking to have the main content begin beneath the menu when the user is at the top of the page, but when the user scrolls down, then it doesn't matter if the menu goes over the top of the content.



Summary:




  • I wish to have a fixed position menu at the top of the page which follows the user when scrolling.

  • Content must appear BELOW the menu ONLY when the user is at the top of the page.

    • When the user scrolls down, the menu may overlap the content.




Can somebody please explain how to achieve this?



Thank you.



UPDATE:



CSS Code:



#floatingMenu{
clear: both;
position: fixed;
width: 85%;
background-color: #78AB46;
top: 5px;
}


HTML Code:



<div id="floatingMenu">
<a href="http://www.google.com">Test 1</a>
<a href="http://www.google.com">Test 2</a>
<a href="http://www.google.com">Test 3</a>
</div>


At present, I can get the menu to appear at the top of the page and centered by placing it inside my container div. However, the content goes behind the menu. I have set clear: both; and this has not helped.










share|improve this question




















  • 1





    Can I suggest you look at this for a good implementation of what you're looking for? twitter.github.com/bootstrap A great starter for good css practices in general too.

    – Finnnn
    Sep 13 '11 at 13:39


















42















My intention is to create a menu at the top of the page which remains at the top of the page even when the user scrolls (like Gmail's recent feature which has the commonly-used buttons scrolling down with the user so that it allows them to perform operations on messages without having to scroll to the top of the page).



I would also like to set the content below said menu to appear below it - at present, it appears behind it.



I am aiming for something like this:



+________________________+
| MENU | <--- Fixed menu - stays at top even when scrolling.
+¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬+
| CONTENT BEGINS |
| HERE |
| |
| |
| |
| |
| |
| |
+¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬+ <--- Bottom of page.


I hope to have the menu at the top which never moves and which stays at the top of the page, even when the user scrolls down. I am also looking to have the main content begin beneath the menu when the user is at the top of the page, but when the user scrolls down, then it doesn't matter if the menu goes over the top of the content.



Summary:




  • I wish to have a fixed position menu at the top of the page which follows the user when scrolling.

  • Content must appear BELOW the menu ONLY when the user is at the top of the page.

    • When the user scrolls down, the menu may overlap the content.




Can somebody please explain how to achieve this?



Thank you.



UPDATE:



CSS Code:



#floatingMenu{
clear: both;
position: fixed;
width: 85%;
background-color: #78AB46;
top: 5px;
}


HTML Code:



<div id="floatingMenu">
<a href="http://www.google.com">Test 1</a>
<a href="http://www.google.com">Test 2</a>
<a href="http://www.google.com">Test 3</a>
</div>


At present, I can get the menu to appear at the top of the page and centered by placing it inside my container div. However, the content goes behind the menu. I have set clear: both; and this has not helped.










share|improve this question




















  • 1





    Can I suggest you look at this for a good implementation of what you're looking for? twitter.github.com/bootstrap A great starter for good css practices in general too.

    – Finnnn
    Sep 13 '11 at 13:39
















42












42








42


11






My intention is to create a menu at the top of the page which remains at the top of the page even when the user scrolls (like Gmail's recent feature which has the commonly-used buttons scrolling down with the user so that it allows them to perform operations on messages without having to scroll to the top of the page).



I would also like to set the content below said menu to appear below it - at present, it appears behind it.



I am aiming for something like this:



+________________________+
| MENU | <--- Fixed menu - stays at top even when scrolling.
+¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬+
| CONTENT BEGINS |
| HERE |
| |
| |
| |
| |
| |
| |
+¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬+ <--- Bottom of page.


I hope to have the menu at the top which never moves and which stays at the top of the page, even when the user scrolls down. I am also looking to have the main content begin beneath the menu when the user is at the top of the page, but when the user scrolls down, then it doesn't matter if the menu goes over the top of the content.



Summary:




  • I wish to have a fixed position menu at the top of the page which follows the user when scrolling.

  • Content must appear BELOW the menu ONLY when the user is at the top of the page.

    • When the user scrolls down, the menu may overlap the content.




Can somebody please explain how to achieve this?



Thank you.



UPDATE:



CSS Code:



#floatingMenu{
clear: both;
position: fixed;
width: 85%;
background-color: #78AB46;
top: 5px;
}


HTML Code:



<div id="floatingMenu">
<a href="http://www.google.com">Test 1</a>
<a href="http://www.google.com">Test 2</a>
<a href="http://www.google.com">Test 3</a>
</div>


At present, I can get the menu to appear at the top of the page and centered by placing it inside my container div. However, the content goes behind the menu. I have set clear: both; and this has not helped.










share|improve this question
















My intention is to create a menu at the top of the page which remains at the top of the page even when the user scrolls (like Gmail's recent feature which has the commonly-used buttons scrolling down with the user so that it allows them to perform operations on messages without having to scroll to the top of the page).



I would also like to set the content below said menu to appear below it - at present, it appears behind it.



I am aiming for something like this:



+________________________+
| MENU | <--- Fixed menu - stays at top even when scrolling.
+¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬+
| CONTENT BEGINS |
| HERE |
| |
| |
| |
| |
| |
| |
+¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬+ <--- Bottom of page.


I hope to have the menu at the top which never moves and which stays at the top of the page, even when the user scrolls down. I am also looking to have the main content begin beneath the menu when the user is at the top of the page, but when the user scrolls down, then it doesn't matter if the menu goes over the top of the content.



Summary:




  • I wish to have a fixed position menu at the top of the page which follows the user when scrolling.

  • Content must appear BELOW the menu ONLY when the user is at the top of the page.

    • When the user scrolls down, the menu may overlap the content.




Can somebody please explain how to achieve this?



Thank you.



UPDATE:



CSS Code:



#floatingMenu{
clear: both;
position: fixed;
width: 85%;
background-color: #78AB46;
top: 5px;
}


HTML Code:



<div id="floatingMenu">
<a href="http://www.google.com">Test 1</a>
<a href="http://www.google.com">Test 2</a>
<a href="http://www.google.com">Test 3</a>
</div>


At present, I can get the menu to appear at the top of the page and centered by placing it inside my container div. However, the content goes behind the menu. I have set clear: both; and this has not helped.







css menu






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 11:26







MusTheDataGuy

















asked Sep 13 '11 at 13:25









MusTheDataGuyMusTheDataGuy

2,192185492




2,192185492








  • 1





    Can I suggest you look at this for a good implementation of what you're looking for? twitter.github.com/bootstrap A great starter for good css practices in general too.

    – Finnnn
    Sep 13 '11 at 13:39
















  • 1





    Can I suggest you look at this for a good implementation of what you're looking for? twitter.github.com/bootstrap A great starter for good css practices in general too.

    – Finnnn
    Sep 13 '11 at 13:39










1




1





Can I suggest you look at this for a good implementation of what you're looking for? twitter.github.com/bootstrap A great starter for good css practices in general too.

– Finnnn
Sep 13 '11 at 13:39







Can I suggest you look at this for a good implementation of what you're looking for? twitter.github.com/bootstrap A great starter for good css practices in general too.

– Finnnn
Sep 13 '11 at 13:39














9 Answers
9






active

oldest

votes


















45














What you need is an extra spacing div (as far as I understood your question).



This div will be placed between the menu and content and be the same height as the menu div, paddings included.



HTML



<div id="fixed-menu">
Navigation options or whatever.
</div>
<div class="spacer">
&nbsp;
</div>
<div id="content">
Content.
</div>


CSS



#fixed-menu
{
position: fixed;
width: 100%;
height: 75px;
background-color: #f00;
padding: 10px;
}

.spacer
{
width: 100%;
height: 95px;
}


See my example here.



This works by offsetting the space that would have been occupied by the nav div, but as it has position: fixed; it has been taken out of the document flow.





The preferred method of achieving this effect is by using margin-top: 95px;/*your nav height*/ on your content wrapper.






share|improve this answer





















  • 3





    Is this today still necessary? An extra useless div?

    – MEM
    Sep 19 '14 at 11:45











  • Well no, you can use a top margin to push the content down under the fixed menu.

    – Kyle
    Sep 22 '14 at 7:24






  • 11





    It's really quite disappointing that in the days of responsive design, we still need to hack in a fixed size margin.

    – Phil Lello
    Nov 30 '14 at 9:37






  • 4





    This is still not possible without JavaScript. If you're "position:fixed" header has a variable height (e.g. it increases in height as you shrink the browser window's width and header options wrap)... there is no way, other than JavaScript, to have such a spacer div or margin increase in a synchronized manner with that variable height.

    – Triynko
    Dec 29 '15 at 20:05








  • 2





    @Triynko, if your changes in header height are driven by media queries (screen width breakpoints) like when you use a framework like material design (e.g. layout-sm="column") or twitter bootstrap (e.g. col-md-6), you can simply adjust the padding on your content element according to the same breakpoint(s). Does that make sense?

    – ctb
    Nov 17 '16 at 5:24



















13














If your menu height is variable (for responsiveness or because it's loaded dynamically), you can set the top margin to where the fixed div ends. For example:



CSS



.fixed-header {
width: 100%;
margin: 0 auto;
position: fixed;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
-ms-box-sizing: border-box;
box-sizing: border-box;
z-index: 999;
}


Javascript



$(document).ready(function() {
var contentPlacement = $('#header').position().top + $('#header').height();
$('#content').css('margin-top',contentPlacement);
});


HTML



...
<div id="header" class="fixed-header"></div>
<div id="content">...</div>
...




Here's a fiddle (https://jsfiddle.net/632k9xkv/5/) that goes a little beyond this with both a fixed nav menu and header in an attempt to hopefully make this a useful sample.






share|improve this answer





















  • 1





    I like this answer better than Kyle's, because it addresses the issue of what to do when your header changes height. In that vein, I feel like your header is usually going to change height when your layout framework (material design or bootstrap, etc.) hits a certain media breakpoint. If that's the case, you can just add your own css selector for a matching media query breakpoint to adjust your margin/padding to whatever is appropriate for that screen size.

    – ctb
    Nov 17 '16 at 5:30













  • I think this is a great solution, so that you don't need to specify height in pixels, which makes this approach ideal for a site on a variety of different devices (pc, laptop, tablet, mobile).

    – JeremyCanfield
    Dec 17 '17 at 23:47













  • Totally agree, way better approach.

    – Kyle
    Nov 30 '18 at 8:45



















6














Having just struggled with this and disliking some of the "hackier" solutions, I found this to be useful and clean:



#floatingMenu{
position: sticky;
top: 0;
}





share|improve this answer


























  • AWESOME! didn't know about position: sticky! Wait a minute my menu is staying sticky for a bit then it scrolls off the page the more i scroll. will need to experiment more.

    – Nick Timmer
    Nov 22 '17 at 22:50













  • This is a great solution, but it isn't currently supported in all browsers: caniuse.com/#feat=css-sticky :-(

    – Rich
    Nov 9 '18 at 14:55











  • Be careful with sticky! If you have long nested menus in the header (usually), this can make some items inaccessible if they fall outside of the screen. It is great for smaller compact menus and alike, though.

    – dev101
    Dec 18 '18 at 1:01











  • In order for sticky to work your parent element must not have any overflow property, otherwise it will not work. stackoverflow.com/a/44929597/2175373

    – T0plomj3r
    Jan 14 at 13:21



















5














I just had this problem, and this was my solution:



#floatingMenu + * {
margin-top: 35px;
}


Adjust for the height of your floatingMenu. If you don't know for sure that it's a div following then you can use * rather than div. This is all valid CSS2.






share|improve this answer
























  • Well thought :)

    – Davi Lima
    Apr 5 '17 at 10:15



















2














Wrap the menu contents with another div:



<div id="floatingMenu">
<div>
<a href="http://www.google.com">Test 1</a>
<a href="http://www.google.com">Test 2</a>
<a href="http://www.google.com">Test 3</a>
</div>
</div>


And the CSS:



#floatingMenu {
clear: both;
position: fixed;
width: 100%;
height: 30px;
background-color: #78AB46;
top: 5px;
}

#floatingMenu > div {
margin: auto;
text-align: center;
}


And about your page below the menu, you can give it a padding-top as well:



#content {
padding-top: 35px; /* top 5px plus height 30px */
}





share|improve this answer


























  • Thank you, this is great - I had just done that before you posted your answer, but thank you for the help.

    – MusTheDataGuy
    Sep 13 '11 at 13:35






  • 1





    @Mick, I updated the answer after your change. Look to see if it works for you.

    – Erick Petrucelli
    Sep 13 '11 at 13:42



















2














I just added a padding-top to the div below the nav. Hope it helps. I'm new on this. C:



#nav {
position: fixed;
top: 0;
left: 0;
width: 100%;
margin: 0 auto;
padding: 0;
background: url(../css/patterns/black_denim.png);
z-index: 9999;
}

#container {
display: block;
padding: 6em 0 3em;
}





share|improve this answer
























  • Unrelated, but z-index: 9999 is probably not helpful and will get you into real trouble with frameworks like bootstrap, material design, etc.. In general, z-index is really easy to lose track of and becomes a real pain to troubleshoot.

    – ctb
    Nov 17 '16 at 4:54



















1














To those suggesting the use of margin-top or padding-top to move the main division below the fixed menu - you don't seem to be testing it completely.



If you set a margin or padding, it will scroll with the page and you will lose lines - go try this page



Looks good, does it not? Highlight a word on the bottom visible line and press page-down - the line with the highlighted word, and a few other lines, will be scrolled under the fixed division.



Margin-top or padding-top WILL position the main division below the fixed division but it all falls flat on its face when you page-down or click the scroll bar to scroll one viewport height of the page.



Same problem if you page-up, lines "fall off" the bottom of the view-port.



Does anyone have an actual fix for THIS problem?



I know how to position things - that's fairly easy if you know the basics about margins, padding, etc. - but how do you prevent the loss of lines when scrolling?



I've looked at a lot of examples of what are claimed to be a properly functioning pages with fixed divisions at the top, but they don't work! They all have problems which scrolling.



I have come across some pages appear to work but if the fixed division is made higher, lines will be lost. I believe I know why they appear to work.



Think in terms of how text on a totally normal (no fancy formatting) page scrolls. Do you see the bottom line when you scroll up or do you see the next line - the bottom one having scrolled off the top of the viewport?



Answer - you see the bottom line scrolled to become the top line.



The fixed menu pages that seem to work really don't. Scroll them and the bottom line is scrolled off the viewport but since the next line is visible, it appears that the fixed division works - but we know better, don't we?



If the fixed division gets higher than the height of one line of text, they fail and lines are lost.



The only pages that I've seen that actually work properly are on sites such as yahoo and I don't have the time, nor inclination, to dig down into what is a lot of CSS, HTML, and JavaScript on the pages to get to the heart of the matter.



So - go to that page and see if you can make changes ("inspect" the elements and make changes to the CSS rules) that fix the scrolling problems.



If you can, come back and share your discovery with world.



My page is a good place to look at what it takes to be able to fix a division at the top, center it (and the main division) and restrict it to a max-width. It may help some of you but I'm sorry I don't have a fix for the scrolling problem



Play with the height of the fix division - make it short enough so that only one line shows and then play with the scrolling. Then make it large enough for two lines and then three and play with the scrolling. You'll see the issues.



Here is a page that is supposed to work but it doesn't - read the very last comment - they describe the problem in a different way but it is the same problem



I just tested the page again in Chrome and it seems to work fairly satisfactorily. With FF the problem exists. Haven't tried IE again, yet.



So - what is different with FF?



Here's a page at cNet which works with chrome and ff - so what are they doing?



More testing with Chrome shows that it fails to fully display the bottom line when scrolled. Just part of the line that was at the bottom is visiable when your scroll - so, still need a fix.






share|improve this answer

































    1














    #nav{
    position: -webkit-sticky; /* Safari */
    position: sticky;
    top: 0;
    margin: 0 auto;
    z-index: 9999;
    background-color: white;
    }





    share|improve this answer


























    • Please add a description, why this is an answer to the question.

      – Poul Bak
      Nov 13 '18 at 22:13











    • This is supper supper cool answer ! Thanks a million you have made my day, as per above request what make this solution of yours works !

      – mwangaben
      Jan 3 at 7:45





















    0














    You should try that Pen I hope that will help you and even give more better functionality to use fixed navigation



    1.clear:both; you dont need to use clear






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f7402635%2fhow-can-i-make-content-appear-beneath-a-fixed-div-element%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      9 Answers
      9






      active

      oldest

      votes








      9 Answers
      9






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      45














      What you need is an extra spacing div (as far as I understood your question).



      This div will be placed between the menu and content and be the same height as the menu div, paddings included.



      HTML



      <div id="fixed-menu">
      Navigation options or whatever.
      </div>
      <div class="spacer">
      &nbsp;
      </div>
      <div id="content">
      Content.
      </div>


      CSS



      #fixed-menu
      {
      position: fixed;
      width: 100%;
      height: 75px;
      background-color: #f00;
      padding: 10px;
      }

      .spacer
      {
      width: 100%;
      height: 95px;
      }


      See my example here.



      This works by offsetting the space that would have been occupied by the nav div, but as it has position: fixed; it has been taken out of the document flow.





      The preferred method of achieving this effect is by using margin-top: 95px;/*your nav height*/ on your content wrapper.






      share|improve this answer





















      • 3





        Is this today still necessary? An extra useless div?

        – MEM
        Sep 19 '14 at 11:45











      • Well no, you can use a top margin to push the content down under the fixed menu.

        – Kyle
        Sep 22 '14 at 7:24






      • 11





        It's really quite disappointing that in the days of responsive design, we still need to hack in a fixed size margin.

        – Phil Lello
        Nov 30 '14 at 9:37






      • 4





        This is still not possible without JavaScript. If you're "position:fixed" header has a variable height (e.g. it increases in height as you shrink the browser window's width and header options wrap)... there is no way, other than JavaScript, to have such a spacer div or margin increase in a synchronized manner with that variable height.

        – Triynko
        Dec 29 '15 at 20:05








      • 2





        @Triynko, if your changes in header height are driven by media queries (screen width breakpoints) like when you use a framework like material design (e.g. layout-sm="column") or twitter bootstrap (e.g. col-md-6), you can simply adjust the padding on your content element according to the same breakpoint(s). Does that make sense?

        – ctb
        Nov 17 '16 at 5:24
















      45














      What you need is an extra spacing div (as far as I understood your question).



      This div will be placed between the menu and content and be the same height as the menu div, paddings included.



      HTML



      <div id="fixed-menu">
      Navigation options or whatever.
      </div>
      <div class="spacer">
      &nbsp;
      </div>
      <div id="content">
      Content.
      </div>


      CSS



      #fixed-menu
      {
      position: fixed;
      width: 100%;
      height: 75px;
      background-color: #f00;
      padding: 10px;
      }

      .spacer
      {
      width: 100%;
      height: 95px;
      }


      See my example here.



      This works by offsetting the space that would have been occupied by the nav div, but as it has position: fixed; it has been taken out of the document flow.





      The preferred method of achieving this effect is by using margin-top: 95px;/*your nav height*/ on your content wrapper.






      share|improve this answer





















      • 3





        Is this today still necessary? An extra useless div?

        – MEM
        Sep 19 '14 at 11:45











      • Well no, you can use a top margin to push the content down under the fixed menu.

        – Kyle
        Sep 22 '14 at 7:24






      • 11





        It's really quite disappointing that in the days of responsive design, we still need to hack in a fixed size margin.

        – Phil Lello
        Nov 30 '14 at 9:37






      • 4





        This is still not possible without JavaScript. If you're "position:fixed" header has a variable height (e.g. it increases in height as you shrink the browser window's width and header options wrap)... there is no way, other than JavaScript, to have such a spacer div or margin increase in a synchronized manner with that variable height.

        – Triynko
        Dec 29 '15 at 20:05








      • 2





        @Triynko, if your changes in header height are driven by media queries (screen width breakpoints) like when you use a framework like material design (e.g. layout-sm="column") or twitter bootstrap (e.g. col-md-6), you can simply adjust the padding on your content element according to the same breakpoint(s). Does that make sense?

        – ctb
        Nov 17 '16 at 5:24














      45












      45








      45







      What you need is an extra spacing div (as far as I understood your question).



      This div will be placed between the menu and content and be the same height as the menu div, paddings included.



      HTML



      <div id="fixed-menu">
      Navigation options or whatever.
      </div>
      <div class="spacer">
      &nbsp;
      </div>
      <div id="content">
      Content.
      </div>


      CSS



      #fixed-menu
      {
      position: fixed;
      width: 100%;
      height: 75px;
      background-color: #f00;
      padding: 10px;
      }

      .spacer
      {
      width: 100%;
      height: 95px;
      }


      See my example here.



      This works by offsetting the space that would have been occupied by the nav div, but as it has position: fixed; it has been taken out of the document flow.





      The preferred method of achieving this effect is by using margin-top: 95px;/*your nav height*/ on your content wrapper.






      share|improve this answer















      What you need is an extra spacing div (as far as I understood your question).



      This div will be placed between the menu and content and be the same height as the menu div, paddings included.



      HTML



      <div id="fixed-menu">
      Navigation options or whatever.
      </div>
      <div class="spacer">
      &nbsp;
      </div>
      <div id="content">
      Content.
      </div>


      CSS



      #fixed-menu
      {
      position: fixed;
      width: 100%;
      height: 75px;
      background-color: #f00;
      padding: 10px;
      }

      .spacer
      {
      width: 100%;
      height: 95px;
      }


      See my example here.



      This works by offsetting the space that would have been occupied by the nav div, but as it has position: fixed; it has been taken out of the document flow.





      The preferred method of achieving this effect is by using margin-top: 95px;/*your nav height*/ on your content wrapper.







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Nov 17 '16 at 8:19

























      answered Sep 13 '11 at 13:35









      KyleKyle

      48.4k27132146




      48.4k27132146








      • 3





        Is this today still necessary? An extra useless div?

        – MEM
        Sep 19 '14 at 11:45











      • Well no, you can use a top margin to push the content down under the fixed menu.

        – Kyle
        Sep 22 '14 at 7:24






      • 11





        It's really quite disappointing that in the days of responsive design, we still need to hack in a fixed size margin.

        – Phil Lello
        Nov 30 '14 at 9:37






      • 4





        This is still not possible without JavaScript. If you're "position:fixed" header has a variable height (e.g. it increases in height as you shrink the browser window's width and header options wrap)... there is no way, other than JavaScript, to have such a spacer div or margin increase in a synchronized manner with that variable height.

        – Triynko
        Dec 29 '15 at 20:05








      • 2





        @Triynko, if your changes in header height are driven by media queries (screen width breakpoints) like when you use a framework like material design (e.g. layout-sm="column") or twitter bootstrap (e.g. col-md-6), you can simply adjust the padding on your content element according to the same breakpoint(s). Does that make sense?

        – ctb
        Nov 17 '16 at 5:24














      • 3





        Is this today still necessary? An extra useless div?

        – MEM
        Sep 19 '14 at 11:45











      • Well no, you can use a top margin to push the content down under the fixed menu.

        – Kyle
        Sep 22 '14 at 7:24






      • 11





        It's really quite disappointing that in the days of responsive design, we still need to hack in a fixed size margin.

        – Phil Lello
        Nov 30 '14 at 9:37






      • 4





        This is still not possible without JavaScript. If you're "position:fixed" header has a variable height (e.g. it increases in height as you shrink the browser window's width and header options wrap)... there is no way, other than JavaScript, to have such a spacer div or margin increase in a synchronized manner with that variable height.

        – Triynko
        Dec 29 '15 at 20:05








      • 2





        @Triynko, if your changes in header height are driven by media queries (screen width breakpoints) like when you use a framework like material design (e.g. layout-sm="column") or twitter bootstrap (e.g. col-md-6), you can simply adjust the padding on your content element according to the same breakpoint(s). Does that make sense?

        – ctb
        Nov 17 '16 at 5:24








      3




      3





      Is this today still necessary? An extra useless div?

      – MEM
      Sep 19 '14 at 11:45





      Is this today still necessary? An extra useless div?

      – MEM
      Sep 19 '14 at 11:45













      Well no, you can use a top margin to push the content down under the fixed menu.

      – Kyle
      Sep 22 '14 at 7:24





      Well no, you can use a top margin to push the content down under the fixed menu.

      – Kyle
      Sep 22 '14 at 7:24




      11




      11





      It's really quite disappointing that in the days of responsive design, we still need to hack in a fixed size margin.

      – Phil Lello
      Nov 30 '14 at 9:37





      It's really quite disappointing that in the days of responsive design, we still need to hack in a fixed size margin.

      – Phil Lello
      Nov 30 '14 at 9:37




      4




      4





      This is still not possible without JavaScript. If you're "position:fixed" header has a variable height (e.g. it increases in height as you shrink the browser window's width and header options wrap)... there is no way, other than JavaScript, to have such a spacer div or margin increase in a synchronized manner with that variable height.

      – Triynko
      Dec 29 '15 at 20:05







      This is still not possible without JavaScript. If you're "position:fixed" header has a variable height (e.g. it increases in height as you shrink the browser window's width and header options wrap)... there is no way, other than JavaScript, to have such a spacer div or margin increase in a synchronized manner with that variable height.

      – Triynko
      Dec 29 '15 at 20:05






      2




      2





      @Triynko, if your changes in header height are driven by media queries (screen width breakpoints) like when you use a framework like material design (e.g. layout-sm="column") or twitter bootstrap (e.g. col-md-6), you can simply adjust the padding on your content element according to the same breakpoint(s). Does that make sense?

      – ctb
      Nov 17 '16 at 5:24





      @Triynko, if your changes in header height are driven by media queries (screen width breakpoints) like when you use a framework like material design (e.g. layout-sm="column") or twitter bootstrap (e.g. col-md-6), you can simply adjust the padding on your content element according to the same breakpoint(s). Does that make sense?

      – ctb
      Nov 17 '16 at 5:24













      13














      If your menu height is variable (for responsiveness or because it's loaded dynamically), you can set the top margin to where the fixed div ends. For example:



      CSS



      .fixed-header {
      width: 100%;
      margin: 0 auto;
      position: fixed;
      -webkit-box-sizing: border-box;
      -moz-box-sizing: border-box;
      -ms-box-sizing: border-box;
      box-sizing: border-box;
      z-index: 999;
      }


      Javascript



      $(document).ready(function() {
      var contentPlacement = $('#header').position().top + $('#header').height();
      $('#content').css('margin-top',contentPlacement);
      });


      HTML



      ...
      <div id="header" class="fixed-header"></div>
      <div id="content">...</div>
      ...




      Here's a fiddle (https://jsfiddle.net/632k9xkv/5/) that goes a little beyond this with both a fixed nav menu and header in an attempt to hopefully make this a useful sample.






      share|improve this answer





















      • 1





        I like this answer better than Kyle's, because it addresses the issue of what to do when your header changes height. In that vein, I feel like your header is usually going to change height when your layout framework (material design or bootstrap, etc.) hits a certain media breakpoint. If that's the case, you can just add your own css selector for a matching media query breakpoint to adjust your margin/padding to whatever is appropriate for that screen size.

        – ctb
        Nov 17 '16 at 5:30













      • I think this is a great solution, so that you don't need to specify height in pixels, which makes this approach ideal for a site on a variety of different devices (pc, laptop, tablet, mobile).

        – JeremyCanfield
        Dec 17 '17 at 23:47













      • Totally agree, way better approach.

        – Kyle
        Nov 30 '18 at 8:45
















      13














      If your menu height is variable (for responsiveness or because it's loaded dynamically), you can set the top margin to where the fixed div ends. For example:



      CSS



      .fixed-header {
      width: 100%;
      margin: 0 auto;
      position: fixed;
      -webkit-box-sizing: border-box;
      -moz-box-sizing: border-box;
      -ms-box-sizing: border-box;
      box-sizing: border-box;
      z-index: 999;
      }


      Javascript



      $(document).ready(function() {
      var contentPlacement = $('#header').position().top + $('#header').height();
      $('#content').css('margin-top',contentPlacement);
      });


      HTML



      ...
      <div id="header" class="fixed-header"></div>
      <div id="content">...</div>
      ...




      Here's a fiddle (https://jsfiddle.net/632k9xkv/5/) that goes a little beyond this with both a fixed nav menu and header in an attempt to hopefully make this a useful sample.






      share|improve this answer





















      • 1





        I like this answer better than Kyle's, because it addresses the issue of what to do when your header changes height. In that vein, I feel like your header is usually going to change height when your layout framework (material design or bootstrap, etc.) hits a certain media breakpoint. If that's the case, you can just add your own css selector for a matching media query breakpoint to adjust your margin/padding to whatever is appropriate for that screen size.

        – ctb
        Nov 17 '16 at 5:30













      • I think this is a great solution, so that you don't need to specify height in pixels, which makes this approach ideal for a site on a variety of different devices (pc, laptop, tablet, mobile).

        – JeremyCanfield
        Dec 17 '17 at 23:47













      • Totally agree, way better approach.

        – Kyle
        Nov 30 '18 at 8:45














      13












      13








      13







      If your menu height is variable (for responsiveness or because it's loaded dynamically), you can set the top margin to where the fixed div ends. For example:



      CSS



      .fixed-header {
      width: 100%;
      margin: 0 auto;
      position: fixed;
      -webkit-box-sizing: border-box;
      -moz-box-sizing: border-box;
      -ms-box-sizing: border-box;
      box-sizing: border-box;
      z-index: 999;
      }


      Javascript



      $(document).ready(function() {
      var contentPlacement = $('#header').position().top + $('#header').height();
      $('#content').css('margin-top',contentPlacement);
      });


      HTML



      ...
      <div id="header" class="fixed-header"></div>
      <div id="content">...</div>
      ...




      Here's a fiddle (https://jsfiddle.net/632k9xkv/5/) that goes a little beyond this with both a fixed nav menu and header in an attempt to hopefully make this a useful sample.






      share|improve this answer















      If your menu height is variable (for responsiveness or because it's loaded dynamically), you can set the top margin to where the fixed div ends. For example:



      CSS



      .fixed-header {
      width: 100%;
      margin: 0 auto;
      position: fixed;
      -webkit-box-sizing: border-box;
      -moz-box-sizing: border-box;
      -ms-box-sizing: border-box;
      box-sizing: border-box;
      z-index: 999;
      }


      Javascript



      $(document).ready(function() {
      var contentPlacement = $('#header').position().top + $('#header').height();
      $('#content').css('margin-top',contentPlacement);
      });


      HTML



      ...
      <div id="header" class="fixed-header"></div>
      <div id="content">...</div>
      ...




      Here's a fiddle (https://jsfiddle.net/632k9xkv/5/) that goes a little beyond this with both a fixed nav menu and header in an attempt to hopefully make this a useful sample.







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited May 28 '15 at 13:54

























      answered May 27 '15 at 17:25









      grdevphlgrdevphl

      5781516




      5781516








      • 1





        I like this answer better than Kyle's, because it addresses the issue of what to do when your header changes height. In that vein, I feel like your header is usually going to change height when your layout framework (material design or bootstrap, etc.) hits a certain media breakpoint. If that's the case, you can just add your own css selector for a matching media query breakpoint to adjust your margin/padding to whatever is appropriate for that screen size.

        – ctb
        Nov 17 '16 at 5:30













      • I think this is a great solution, so that you don't need to specify height in pixels, which makes this approach ideal for a site on a variety of different devices (pc, laptop, tablet, mobile).

        – JeremyCanfield
        Dec 17 '17 at 23:47













      • Totally agree, way better approach.

        – Kyle
        Nov 30 '18 at 8:45














      • 1





        I like this answer better than Kyle's, because it addresses the issue of what to do when your header changes height. In that vein, I feel like your header is usually going to change height when your layout framework (material design or bootstrap, etc.) hits a certain media breakpoint. If that's the case, you can just add your own css selector for a matching media query breakpoint to adjust your margin/padding to whatever is appropriate for that screen size.

        – ctb
        Nov 17 '16 at 5:30













      • I think this is a great solution, so that you don't need to specify height in pixels, which makes this approach ideal for a site on a variety of different devices (pc, laptop, tablet, mobile).

        – JeremyCanfield
        Dec 17 '17 at 23:47













      • Totally agree, way better approach.

        – Kyle
        Nov 30 '18 at 8:45








      1




      1





      I like this answer better than Kyle's, because it addresses the issue of what to do when your header changes height. In that vein, I feel like your header is usually going to change height when your layout framework (material design or bootstrap, etc.) hits a certain media breakpoint. If that's the case, you can just add your own css selector for a matching media query breakpoint to adjust your margin/padding to whatever is appropriate for that screen size.

      – ctb
      Nov 17 '16 at 5:30







      I like this answer better than Kyle's, because it addresses the issue of what to do when your header changes height. In that vein, I feel like your header is usually going to change height when your layout framework (material design or bootstrap, etc.) hits a certain media breakpoint. If that's the case, you can just add your own css selector for a matching media query breakpoint to adjust your margin/padding to whatever is appropriate for that screen size.

      – ctb
      Nov 17 '16 at 5:30















      I think this is a great solution, so that you don't need to specify height in pixels, which makes this approach ideal for a site on a variety of different devices (pc, laptop, tablet, mobile).

      – JeremyCanfield
      Dec 17 '17 at 23:47







      I think this is a great solution, so that you don't need to specify height in pixels, which makes this approach ideal for a site on a variety of different devices (pc, laptop, tablet, mobile).

      – JeremyCanfield
      Dec 17 '17 at 23:47















      Totally agree, way better approach.

      – Kyle
      Nov 30 '18 at 8:45





      Totally agree, way better approach.

      – Kyle
      Nov 30 '18 at 8:45











      6














      Having just struggled with this and disliking some of the "hackier" solutions, I found this to be useful and clean:



      #floatingMenu{
      position: sticky;
      top: 0;
      }





      share|improve this answer


























      • AWESOME! didn't know about position: sticky! Wait a minute my menu is staying sticky for a bit then it scrolls off the page the more i scroll. will need to experiment more.

        – Nick Timmer
        Nov 22 '17 at 22:50













      • This is a great solution, but it isn't currently supported in all browsers: caniuse.com/#feat=css-sticky :-(

        – Rich
        Nov 9 '18 at 14:55











      • Be careful with sticky! If you have long nested menus in the header (usually), this can make some items inaccessible if they fall outside of the screen. It is great for smaller compact menus and alike, though.

        – dev101
        Dec 18 '18 at 1:01











      • In order for sticky to work your parent element must not have any overflow property, otherwise it will not work. stackoverflow.com/a/44929597/2175373

        – T0plomj3r
        Jan 14 at 13:21
















      6














      Having just struggled with this and disliking some of the "hackier" solutions, I found this to be useful and clean:



      #floatingMenu{
      position: sticky;
      top: 0;
      }





      share|improve this answer


























      • AWESOME! didn't know about position: sticky! Wait a minute my menu is staying sticky for a bit then it scrolls off the page the more i scroll. will need to experiment more.

        – Nick Timmer
        Nov 22 '17 at 22:50













      • This is a great solution, but it isn't currently supported in all browsers: caniuse.com/#feat=css-sticky :-(

        – Rich
        Nov 9 '18 at 14:55











      • Be careful with sticky! If you have long nested menus in the header (usually), this can make some items inaccessible if they fall outside of the screen. It is great for smaller compact menus and alike, though.

        – dev101
        Dec 18 '18 at 1:01











      • In order for sticky to work your parent element must not have any overflow property, otherwise it will not work. stackoverflow.com/a/44929597/2175373

        – T0plomj3r
        Jan 14 at 13:21














      6












      6








      6







      Having just struggled with this and disliking some of the "hackier" solutions, I found this to be useful and clean:



      #floatingMenu{
      position: sticky;
      top: 0;
      }





      share|improve this answer















      Having just struggled with this and disliking some of the "hackier" solutions, I found this to be useful and clean:



      #floatingMenu{
      position: sticky;
      top: 0;
      }






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Oct 28 '17 at 12:17

























      answered Oct 28 '17 at 12:09









      ahanusaahanusa

      344149




      344149













      • AWESOME! didn't know about position: sticky! Wait a minute my menu is staying sticky for a bit then it scrolls off the page the more i scroll. will need to experiment more.

        – Nick Timmer
        Nov 22 '17 at 22:50













      • This is a great solution, but it isn't currently supported in all browsers: caniuse.com/#feat=css-sticky :-(

        – Rich
        Nov 9 '18 at 14:55











      • Be careful with sticky! If you have long nested menus in the header (usually), this can make some items inaccessible if they fall outside of the screen. It is great for smaller compact menus and alike, though.

        – dev101
        Dec 18 '18 at 1:01











      • In order for sticky to work your parent element must not have any overflow property, otherwise it will not work. stackoverflow.com/a/44929597/2175373

        – T0plomj3r
        Jan 14 at 13:21



















      • AWESOME! didn't know about position: sticky! Wait a minute my menu is staying sticky for a bit then it scrolls off the page the more i scroll. will need to experiment more.

        – Nick Timmer
        Nov 22 '17 at 22:50













      • This is a great solution, but it isn't currently supported in all browsers: caniuse.com/#feat=css-sticky :-(

        – Rich
        Nov 9 '18 at 14:55











      • Be careful with sticky! If you have long nested menus in the header (usually), this can make some items inaccessible if they fall outside of the screen. It is great for smaller compact menus and alike, though.

        – dev101
        Dec 18 '18 at 1:01











      • In order for sticky to work your parent element must not have any overflow property, otherwise it will not work. stackoverflow.com/a/44929597/2175373

        – T0plomj3r
        Jan 14 at 13:21

















      AWESOME! didn't know about position: sticky! Wait a minute my menu is staying sticky for a bit then it scrolls off the page the more i scroll. will need to experiment more.

      – Nick Timmer
      Nov 22 '17 at 22:50







      AWESOME! didn't know about position: sticky! Wait a minute my menu is staying sticky for a bit then it scrolls off the page the more i scroll. will need to experiment more.

      – Nick Timmer
      Nov 22 '17 at 22:50















      This is a great solution, but it isn't currently supported in all browsers: caniuse.com/#feat=css-sticky :-(

      – Rich
      Nov 9 '18 at 14:55





      This is a great solution, but it isn't currently supported in all browsers: caniuse.com/#feat=css-sticky :-(

      – Rich
      Nov 9 '18 at 14:55













      Be careful with sticky! If you have long nested menus in the header (usually), this can make some items inaccessible if they fall outside of the screen. It is great for smaller compact menus and alike, though.

      – dev101
      Dec 18 '18 at 1:01





      Be careful with sticky! If you have long nested menus in the header (usually), this can make some items inaccessible if they fall outside of the screen. It is great for smaller compact menus and alike, though.

      – dev101
      Dec 18 '18 at 1:01













      In order for sticky to work your parent element must not have any overflow property, otherwise it will not work. stackoverflow.com/a/44929597/2175373

      – T0plomj3r
      Jan 14 at 13:21





      In order for sticky to work your parent element must not have any overflow property, otherwise it will not work. stackoverflow.com/a/44929597/2175373

      – T0plomj3r
      Jan 14 at 13:21











      5














      I just had this problem, and this was my solution:



      #floatingMenu + * {
      margin-top: 35px;
      }


      Adjust for the height of your floatingMenu. If you don't know for sure that it's a div following then you can use * rather than div. This is all valid CSS2.






      share|improve this answer
























      • Well thought :)

        – Davi Lima
        Apr 5 '17 at 10:15
















      5














      I just had this problem, and this was my solution:



      #floatingMenu + * {
      margin-top: 35px;
      }


      Adjust for the height of your floatingMenu. If you don't know for sure that it's a div following then you can use * rather than div. This is all valid CSS2.






      share|improve this answer
























      • Well thought :)

        – Davi Lima
        Apr 5 '17 at 10:15














      5












      5








      5







      I just had this problem, and this was my solution:



      #floatingMenu + * {
      margin-top: 35px;
      }


      Adjust for the height of your floatingMenu. If you don't know for sure that it's a div following then you can use * rather than div. This is all valid CSS2.






      share|improve this answer













      I just had this problem, and this was my solution:



      #floatingMenu + * {
      margin-top: 35px;
      }


      Adjust for the height of your floatingMenu. If you don't know for sure that it's a div following then you can use * rather than div. This is all valid CSS2.







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Nov 28 '13 at 13:22









      DanimalDanimal

      1,072819




      1,072819













      • Well thought :)

        – Davi Lima
        Apr 5 '17 at 10:15



















      • Well thought :)

        – Davi Lima
        Apr 5 '17 at 10:15

















      Well thought :)

      – Davi Lima
      Apr 5 '17 at 10:15





      Well thought :)

      – Davi Lima
      Apr 5 '17 at 10:15











      2














      Wrap the menu contents with another div:



      <div id="floatingMenu">
      <div>
      <a href="http://www.google.com">Test 1</a>
      <a href="http://www.google.com">Test 2</a>
      <a href="http://www.google.com">Test 3</a>
      </div>
      </div>


      And the CSS:



      #floatingMenu {
      clear: both;
      position: fixed;
      width: 100%;
      height: 30px;
      background-color: #78AB46;
      top: 5px;
      }

      #floatingMenu > div {
      margin: auto;
      text-align: center;
      }


      And about your page below the menu, you can give it a padding-top as well:



      #content {
      padding-top: 35px; /* top 5px plus height 30px */
      }





      share|improve this answer


























      • Thank you, this is great - I had just done that before you posted your answer, but thank you for the help.

        – MusTheDataGuy
        Sep 13 '11 at 13:35






      • 1





        @Mick, I updated the answer after your change. Look to see if it works for you.

        – Erick Petrucelli
        Sep 13 '11 at 13:42
















      2














      Wrap the menu contents with another div:



      <div id="floatingMenu">
      <div>
      <a href="http://www.google.com">Test 1</a>
      <a href="http://www.google.com">Test 2</a>
      <a href="http://www.google.com">Test 3</a>
      </div>
      </div>


      And the CSS:



      #floatingMenu {
      clear: both;
      position: fixed;
      width: 100%;
      height: 30px;
      background-color: #78AB46;
      top: 5px;
      }

      #floatingMenu > div {
      margin: auto;
      text-align: center;
      }


      And about your page below the menu, you can give it a padding-top as well:



      #content {
      padding-top: 35px; /* top 5px plus height 30px */
      }





      share|improve this answer


























      • Thank you, this is great - I had just done that before you posted your answer, but thank you for the help.

        – MusTheDataGuy
        Sep 13 '11 at 13:35






      • 1





        @Mick, I updated the answer after your change. Look to see if it works for you.

        – Erick Petrucelli
        Sep 13 '11 at 13:42














      2












      2








      2







      Wrap the menu contents with another div:



      <div id="floatingMenu">
      <div>
      <a href="http://www.google.com">Test 1</a>
      <a href="http://www.google.com">Test 2</a>
      <a href="http://www.google.com">Test 3</a>
      </div>
      </div>


      And the CSS:



      #floatingMenu {
      clear: both;
      position: fixed;
      width: 100%;
      height: 30px;
      background-color: #78AB46;
      top: 5px;
      }

      #floatingMenu > div {
      margin: auto;
      text-align: center;
      }


      And about your page below the menu, you can give it a padding-top as well:



      #content {
      padding-top: 35px; /* top 5px plus height 30px */
      }





      share|improve this answer















      Wrap the menu contents with another div:



      <div id="floatingMenu">
      <div>
      <a href="http://www.google.com">Test 1</a>
      <a href="http://www.google.com">Test 2</a>
      <a href="http://www.google.com">Test 3</a>
      </div>
      </div>


      And the CSS:



      #floatingMenu {
      clear: both;
      position: fixed;
      width: 100%;
      height: 30px;
      background-color: #78AB46;
      top: 5px;
      }

      #floatingMenu > div {
      margin: auto;
      text-align: center;
      }


      And about your page below the menu, you can give it a padding-top as well:



      #content {
      padding-top: 35px; /* top 5px plus height 30px */
      }






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Sep 13 '11 at 13:40

























      answered Sep 13 '11 at 13:33









      Erick PetrucelliErick Petrucelli

      10.1k64268




      10.1k64268













      • Thank you, this is great - I had just done that before you posted your answer, but thank you for the help.

        – MusTheDataGuy
        Sep 13 '11 at 13:35






      • 1





        @Mick, I updated the answer after your change. Look to see if it works for you.

        – Erick Petrucelli
        Sep 13 '11 at 13:42



















      • Thank you, this is great - I had just done that before you posted your answer, but thank you for the help.

        – MusTheDataGuy
        Sep 13 '11 at 13:35






      • 1





        @Mick, I updated the answer after your change. Look to see if it works for you.

        – Erick Petrucelli
        Sep 13 '11 at 13:42

















      Thank you, this is great - I had just done that before you posted your answer, but thank you for the help.

      – MusTheDataGuy
      Sep 13 '11 at 13:35





      Thank you, this is great - I had just done that before you posted your answer, but thank you for the help.

      – MusTheDataGuy
      Sep 13 '11 at 13:35




      1




      1





      @Mick, I updated the answer after your change. Look to see if it works for you.

      – Erick Petrucelli
      Sep 13 '11 at 13:42





      @Mick, I updated the answer after your change. Look to see if it works for you.

      – Erick Petrucelli
      Sep 13 '11 at 13:42











      2














      I just added a padding-top to the div below the nav. Hope it helps. I'm new on this. C:



      #nav {
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      margin: 0 auto;
      padding: 0;
      background: url(../css/patterns/black_denim.png);
      z-index: 9999;
      }

      #container {
      display: block;
      padding: 6em 0 3em;
      }





      share|improve this answer
























      • Unrelated, but z-index: 9999 is probably not helpful and will get you into real trouble with frameworks like bootstrap, material design, etc.. In general, z-index is really easy to lose track of and becomes a real pain to troubleshoot.

        – ctb
        Nov 17 '16 at 4:54
















      2














      I just added a padding-top to the div below the nav. Hope it helps. I'm new on this. C:



      #nav {
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      margin: 0 auto;
      padding: 0;
      background: url(../css/patterns/black_denim.png);
      z-index: 9999;
      }

      #container {
      display: block;
      padding: 6em 0 3em;
      }





      share|improve this answer
























      • Unrelated, but z-index: 9999 is probably not helpful and will get you into real trouble with frameworks like bootstrap, material design, etc.. In general, z-index is really easy to lose track of and becomes a real pain to troubleshoot.

        – ctb
        Nov 17 '16 at 4:54














      2












      2








      2







      I just added a padding-top to the div below the nav. Hope it helps. I'm new on this. C:



      #nav {
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      margin: 0 auto;
      padding: 0;
      background: url(../css/patterns/black_denim.png);
      z-index: 9999;
      }

      #container {
      display: block;
      padding: 6em 0 3em;
      }





      share|improve this answer













      I just added a padding-top to the div below the nav. Hope it helps. I'm new on this. C:



      #nav {
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      margin: 0 auto;
      padding: 0;
      background: url(../css/patterns/black_denim.png);
      z-index: 9999;
      }

      #container {
      display: block;
      padding: 6em 0 3em;
      }






      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Apr 30 '15 at 22:08









      user4852538user4852538

      211




      211













      • Unrelated, but z-index: 9999 is probably not helpful and will get you into real trouble with frameworks like bootstrap, material design, etc.. In general, z-index is really easy to lose track of and becomes a real pain to troubleshoot.

        – ctb
        Nov 17 '16 at 4:54



















      • Unrelated, but z-index: 9999 is probably not helpful and will get you into real trouble with frameworks like bootstrap, material design, etc.. In general, z-index is really easy to lose track of and becomes a real pain to troubleshoot.

        – ctb
        Nov 17 '16 at 4:54

















      Unrelated, but z-index: 9999 is probably not helpful and will get you into real trouble with frameworks like bootstrap, material design, etc.. In general, z-index is really easy to lose track of and becomes a real pain to troubleshoot.

      – ctb
      Nov 17 '16 at 4:54





      Unrelated, but z-index: 9999 is probably not helpful and will get you into real trouble with frameworks like bootstrap, material design, etc.. In general, z-index is really easy to lose track of and becomes a real pain to troubleshoot.

      – ctb
      Nov 17 '16 at 4:54











      1














      To those suggesting the use of margin-top or padding-top to move the main division below the fixed menu - you don't seem to be testing it completely.



      If you set a margin or padding, it will scroll with the page and you will lose lines - go try this page



      Looks good, does it not? Highlight a word on the bottom visible line and press page-down - the line with the highlighted word, and a few other lines, will be scrolled under the fixed division.



      Margin-top or padding-top WILL position the main division below the fixed division but it all falls flat on its face when you page-down or click the scroll bar to scroll one viewport height of the page.



      Same problem if you page-up, lines "fall off" the bottom of the view-port.



      Does anyone have an actual fix for THIS problem?



      I know how to position things - that's fairly easy if you know the basics about margins, padding, etc. - but how do you prevent the loss of lines when scrolling?



      I've looked at a lot of examples of what are claimed to be a properly functioning pages with fixed divisions at the top, but they don't work! They all have problems which scrolling.



      I have come across some pages appear to work but if the fixed division is made higher, lines will be lost. I believe I know why they appear to work.



      Think in terms of how text on a totally normal (no fancy formatting) page scrolls. Do you see the bottom line when you scroll up or do you see the next line - the bottom one having scrolled off the top of the viewport?



      Answer - you see the bottom line scrolled to become the top line.



      The fixed menu pages that seem to work really don't. Scroll them and the bottom line is scrolled off the viewport but since the next line is visible, it appears that the fixed division works - but we know better, don't we?



      If the fixed division gets higher than the height of one line of text, they fail and lines are lost.



      The only pages that I've seen that actually work properly are on sites such as yahoo and I don't have the time, nor inclination, to dig down into what is a lot of CSS, HTML, and JavaScript on the pages to get to the heart of the matter.



      So - go to that page and see if you can make changes ("inspect" the elements and make changes to the CSS rules) that fix the scrolling problems.



      If you can, come back and share your discovery with world.



      My page is a good place to look at what it takes to be able to fix a division at the top, center it (and the main division) and restrict it to a max-width. It may help some of you but I'm sorry I don't have a fix for the scrolling problem



      Play with the height of the fix division - make it short enough so that only one line shows and then play with the scrolling. Then make it large enough for two lines and then three and play with the scrolling. You'll see the issues.



      Here is a page that is supposed to work but it doesn't - read the very last comment - they describe the problem in a different way but it is the same problem



      I just tested the page again in Chrome and it seems to work fairly satisfactorily. With FF the problem exists. Haven't tried IE again, yet.



      So - what is different with FF?



      Here's a page at cNet which works with chrome and ff - so what are they doing?



      More testing with Chrome shows that it fails to fully display the bottom line when scrolled. Just part of the line that was at the bottom is visiable when your scroll - so, still need a fix.






      share|improve this answer






























        1














        To those suggesting the use of margin-top or padding-top to move the main division below the fixed menu - you don't seem to be testing it completely.



        If you set a margin or padding, it will scroll with the page and you will lose lines - go try this page



        Looks good, does it not? Highlight a word on the bottom visible line and press page-down - the line with the highlighted word, and a few other lines, will be scrolled under the fixed division.



        Margin-top or padding-top WILL position the main division below the fixed division but it all falls flat on its face when you page-down or click the scroll bar to scroll one viewport height of the page.



        Same problem if you page-up, lines "fall off" the bottom of the view-port.



        Does anyone have an actual fix for THIS problem?



        I know how to position things - that's fairly easy if you know the basics about margins, padding, etc. - but how do you prevent the loss of lines when scrolling?



        I've looked at a lot of examples of what are claimed to be a properly functioning pages with fixed divisions at the top, but they don't work! They all have problems which scrolling.



        I have come across some pages appear to work but if the fixed division is made higher, lines will be lost. I believe I know why they appear to work.



        Think in terms of how text on a totally normal (no fancy formatting) page scrolls. Do you see the bottom line when you scroll up or do you see the next line - the bottom one having scrolled off the top of the viewport?



        Answer - you see the bottom line scrolled to become the top line.



        The fixed menu pages that seem to work really don't. Scroll them and the bottom line is scrolled off the viewport but since the next line is visible, it appears that the fixed division works - but we know better, don't we?



        If the fixed division gets higher than the height of one line of text, they fail and lines are lost.



        The only pages that I've seen that actually work properly are on sites such as yahoo and I don't have the time, nor inclination, to dig down into what is a lot of CSS, HTML, and JavaScript on the pages to get to the heart of the matter.



        So - go to that page and see if you can make changes ("inspect" the elements and make changes to the CSS rules) that fix the scrolling problems.



        If you can, come back and share your discovery with world.



        My page is a good place to look at what it takes to be able to fix a division at the top, center it (and the main division) and restrict it to a max-width. It may help some of you but I'm sorry I don't have a fix for the scrolling problem



        Play with the height of the fix division - make it short enough so that only one line shows and then play with the scrolling. Then make it large enough for two lines and then three and play with the scrolling. You'll see the issues.



        Here is a page that is supposed to work but it doesn't - read the very last comment - they describe the problem in a different way but it is the same problem



        I just tested the page again in Chrome and it seems to work fairly satisfactorily. With FF the problem exists. Haven't tried IE again, yet.



        So - what is different with FF?



        Here's a page at cNet which works with chrome and ff - so what are they doing?



        More testing with Chrome shows that it fails to fully display the bottom line when scrolled. Just part of the line that was at the bottom is visiable when your scroll - so, still need a fix.






        share|improve this answer




























          1












          1








          1







          To those suggesting the use of margin-top or padding-top to move the main division below the fixed menu - you don't seem to be testing it completely.



          If you set a margin or padding, it will scroll with the page and you will lose lines - go try this page



          Looks good, does it not? Highlight a word on the bottom visible line and press page-down - the line with the highlighted word, and a few other lines, will be scrolled under the fixed division.



          Margin-top or padding-top WILL position the main division below the fixed division but it all falls flat on its face when you page-down or click the scroll bar to scroll one viewport height of the page.



          Same problem if you page-up, lines "fall off" the bottom of the view-port.



          Does anyone have an actual fix for THIS problem?



          I know how to position things - that's fairly easy if you know the basics about margins, padding, etc. - but how do you prevent the loss of lines when scrolling?



          I've looked at a lot of examples of what are claimed to be a properly functioning pages with fixed divisions at the top, but they don't work! They all have problems which scrolling.



          I have come across some pages appear to work but if the fixed division is made higher, lines will be lost. I believe I know why they appear to work.



          Think in terms of how text on a totally normal (no fancy formatting) page scrolls. Do you see the bottom line when you scroll up or do you see the next line - the bottom one having scrolled off the top of the viewport?



          Answer - you see the bottom line scrolled to become the top line.



          The fixed menu pages that seem to work really don't. Scroll them and the bottom line is scrolled off the viewport but since the next line is visible, it appears that the fixed division works - but we know better, don't we?



          If the fixed division gets higher than the height of one line of text, they fail and lines are lost.



          The only pages that I've seen that actually work properly are on sites such as yahoo and I don't have the time, nor inclination, to dig down into what is a lot of CSS, HTML, and JavaScript on the pages to get to the heart of the matter.



          So - go to that page and see if you can make changes ("inspect" the elements and make changes to the CSS rules) that fix the scrolling problems.



          If you can, come back and share your discovery with world.



          My page is a good place to look at what it takes to be able to fix a division at the top, center it (and the main division) and restrict it to a max-width. It may help some of you but I'm sorry I don't have a fix for the scrolling problem



          Play with the height of the fix division - make it short enough so that only one line shows and then play with the scrolling. Then make it large enough for two lines and then three and play with the scrolling. You'll see the issues.



          Here is a page that is supposed to work but it doesn't - read the very last comment - they describe the problem in a different way but it is the same problem



          I just tested the page again in Chrome and it seems to work fairly satisfactorily. With FF the problem exists. Haven't tried IE again, yet.



          So - what is different with FF?



          Here's a page at cNet which works with chrome and ff - so what are they doing?



          More testing with Chrome shows that it fails to fully display the bottom line when scrolled. Just part of the line that was at the bottom is visiable when your scroll - so, still need a fix.






          share|improve this answer















          To those suggesting the use of margin-top or padding-top to move the main division below the fixed menu - you don't seem to be testing it completely.



          If you set a margin or padding, it will scroll with the page and you will lose lines - go try this page



          Looks good, does it not? Highlight a word on the bottom visible line and press page-down - the line with the highlighted word, and a few other lines, will be scrolled under the fixed division.



          Margin-top or padding-top WILL position the main division below the fixed division but it all falls flat on its face when you page-down or click the scroll bar to scroll one viewport height of the page.



          Same problem if you page-up, lines "fall off" the bottom of the view-port.



          Does anyone have an actual fix for THIS problem?



          I know how to position things - that's fairly easy if you know the basics about margins, padding, etc. - but how do you prevent the loss of lines when scrolling?



          I've looked at a lot of examples of what are claimed to be a properly functioning pages with fixed divisions at the top, but they don't work! They all have problems which scrolling.



          I have come across some pages appear to work but if the fixed division is made higher, lines will be lost. I believe I know why they appear to work.



          Think in terms of how text on a totally normal (no fancy formatting) page scrolls. Do you see the bottom line when you scroll up or do you see the next line - the bottom one having scrolled off the top of the viewport?



          Answer - you see the bottom line scrolled to become the top line.



          The fixed menu pages that seem to work really don't. Scroll them and the bottom line is scrolled off the viewport but since the next line is visible, it appears that the fixed division works - but we know better, don't we?



          If the fixed division gets higher than the height of one line of text, they fail and lines are lost.



          The only pages that I've seen that actually work properly are on sites such as yahoo and I don't have the time, nor inclination, to dig down into what is a lot of CSS, HTML, and JavaScript on the pages to get to the heart of the matter.



          So - go to that page and see if you can make changes ("inspect" the elements and make changes to the CSS rules) that fix the scrolling problems.



          If you can, come back and share your discovery with world.



          My page is a good place to look at what it takes to be able to fix a division at the top, center it (and the main division) and restrict it to a max-width. It may help some of you but I'm sorry I don't have a fix for the scrolling problem



          Play with the height of the fix division - make it short enough so that only one line shows and then play with the scrolling. Then make it large enough for two lines and then three and play with the scrolling. You'll see the issues.



          Here is a page that is supposed to work but it doesn't - read the very last comment - they describe the problem in a different way but it is the same problem



          I just tested the page again in Chrome and it seems to work fairly satisfactorily. With FF the problem exists. Haven't tried IE again, yet.



          So - what is different with FF?



          Here's a page at cNet which works with chrome and ff - so what are they doing?



          More testing with Chrome shows that it fails to fully display the bottom line when scrolled. Just part of the line that was at the bottom is visiable when your scroll - so, still need a fix.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Aug 15 '15 at 7:45

























          answered Aug 15 '15 at 6:37









          BobNBobN

          82110




          82110























              1














              #nav{
              position: -webkit-sticky; /* Safari */
              position: sticky;
              top: 0;
              margin: 0 auto;
              z-index: 9999;
              background-color: white;
              }





              share|improve this answer


























              • Please add a description, why this is an answer to the question.

                – Poul Bak
                Nov 13 '18 at 22:13











              • This is supper supper cool answer ! Thanks a million you have made my day, as per above request what make this solution of yours works !

                – mwangaben
                Jan 3 at 7:45


















              1














              #nav{
              position: -webkit-sticky; /* Safari */
              position: sticky;
              top: 0;
              margin: 0 auto;
              z-index: 9999;
              background-color: white;
              }





              share|improve this answer


























              • Please add a description, why this is an answer to the question.

                – Poul Bak
                Nov 13 '18 at 22:13











              • This is supper supper cool answer ! Thanks a million you have made my day, as per above request what make this solution of yours works !

                – mwangaben
                Jan 3 at 7:45
















              1












              1








              1







              #nav{
              position: -webkit-sticky; /* Safari */
              position: sticky;
              top: 0;
              margin: 0 auto;
              z-index: 9999;
              background-color: white;
              }





              share|improve this answer















              #nav{
              position: -webkit-sticky; /* Safari */
              position: sticky;
              top: 0;
              margin: 0 auto;
              z-index: 9999;
              background-color: white;
              }






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Nov 13 '18 at 19:49









              סטנלי גרונן

              1,63472044




              1,63472044










              answered Nov 13 '18 at 18:25









              Hassan SarwarHassan Sarwar

              111




              111













              • Please add a description, why this is an answer to the question.

                – Poul Bak
                Nov 13 '18 at 22:13











              • This is supper supper cool answer ! Thanks a million you have made my day, as per above request what make this solution of yours works !

                – mwangaben
                Jan 3 at 7:45





















              • Please add a description, why this is an answer to the question.

                – Poul Bak
                Nov 13 '18 at 22:13











              • This is supper supper cool answer ! Thanks a million you have made my day, as per above request what make this solution of yours works !

                – mwangaben
                Jan 3 at 7:45



















              Please add a description, why this is an answer to the question.

              – Poul Bak
              Nov 13 '18 at 22:13





              Please add a description, why this is an answer to the question.

              – Poul Bak
              Nov 13 '18 at 22:13













              This is supper supper cool answer ! Thanks a million you have made my day, as per above request what make this solution of yours works !

              – mwangaben
              Jan 3 at 7:45







              This is supper supper cool answer ! Thanks a million you have made my day, as per above request what make this solution of yours works !

              – mwangaben
              Jan 3 at 7:45













              0














              You should try that Pen I hope that will help you and even give more better functionality to use fixed navigation



              1.clear:both; you dont need to use clear






              share|improve this answer




























                0














                You should try that Pen I hope that will help you and even give more better functionality to use fixed navigation



                1.clear:both; you dont need to use clear






                share|improve this answer


























                  0












                  0








                  0







                  You should try that Pen I hope that will help you and even give more better functionality to use fixed navigation



                  1.clear:both; you dont need to use clear






                  share|improve this answer













                  You should try that Pen I hope that will help you and even give more better functionality to use fixed navigation



                  1.clear:both; you dont need to use clear







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Apr 13 '14 at 0:42









                  shaz3eshaz3e

                  11912




                  11912






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f7402635%2fhow-can-i-make-content-appear-beneath-a-fixed-div-element%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Bressuire

                      Vorschmack

                      Quarantine