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 8465687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:07:18+00:00 2026-06-10T15:07:18+00:00

I am trying to center the navigation within the main content div and have

  • 0

I am trying to center the navigation within the main content div and have it stuck there while scrolling. The problem that I just can’t wrap my head around is that it needs to be parallaxy because of the header and the footer. I have a staging environment http://stage.golishlaw.com/portfolio/

I cannot write down everything that I have tried but some of the most recent stuff is:

var _mainHeight = (($(window).height()/2) - ($("#portfolio_nav").height()/2)) + (($("#main").offset().top - $(window).scrollTop()))
$("#portfolio_nav").css({
    top: _mainHeight
});

This one worked well on some monitor sizes but not others.

var mainScrollTop = (($(window).scrollTop() - $("#main").offset().top));
mainScrollTop = mainScrollTop > 0 ? 0 : mainScrollTop;
var _mainHeight =  ((($(window).height() )/2 - $("#portfolio_nav").height()/2) + $("#main").offset().top) + mainScrollTop
$("#portfolio_nav").css({
    top: _mainHeight
});

This one work pretty well to but the nav got stuck at a certain spot (I know why I just can’t figure how to get it stuck in the center of the screen)

I’ve just really been pulling my hair out on this one and I’ve tried everything that I could think of.

  • 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-10T15:07:20+00:00Added an answer on June 10, 2026 at 3:07 pm

    You’re already defining the left position with CSS: absolute; left: 50%; margin-left: -401px; So add this CSS to your #portfolio_nav rule to center it vertically:

    top: 50%;
    margin-top: -80px;
    

    Make sure to comment out the jQuery code which sets the top CSS property otherwise it will override the CSS rule.

    margin-top calc: Each list item has around 40px (height + padding-bottom) so 4 li * 40 = 160 / 2 = -80px margin-top. Or just subtract 20px each time you add a list item. Of course, this calc can be done through jQuery setting the marginTop later if you need to add list items dynamically.

    If you want an even more accurate vertical center, you can do the maths not accounting for the padding-bottom of the last list item as its padding-bottom is not visible. margin-top:-70px is slightly more centered.


    Update to center it vertically in the browser window while respecting the container restriction:

    $(function() {
        var $pnav = $('#portfolio_nav'),
            $w = $(window);
        $pnav.css('top', 0);
        $w.scroll(function() {
            var $p = $pnav.parent(),
                pptop = parseInt($p.css('paddingTop'), 10),
                ppbottom = parseInt($p.css('paddingBottom'), 10),
                pheight = $p.height(),
                pnavheight = $pnav.height();
            $pnav.css('top', $w.height()/2 - ($p.offset().top + pptop) - pnavheight/2 + $w.scrollTop());
    
            var pnavpostop = $pnav.position().top;
            if (pnavpostop < pptop) $pnav.css('top', pptop);
            else if (pnavpostop + pnavheight > pptop + pheight + ppbottom) $pnav.css('top', pheight - pnavheight);
        }).scroll();
    });
    

    Fiddle

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

Sidebar

Related Questions

I'm trying to stretch a navigation arrow image while preserving the edges so that
I have a navigation menu with css. I'm trying to vertically and horizontally center
I am trying to center my navigation links inside the div but no matter
I'm trying to center the navigation on this page: http://66.147.244.50/~schneie1/ However, the div containing
Trying to have a horizontal navigation bar that has equally spaced links spanning across
I have a Silverlight application that is using a navigation frame. I am trying
I am trying to center align my google chart but have been unsuccessful in
I am trying to center my a .img-link tag within a thumbnail but haven't
I am trying to center a launched window in flex, there is a NativeWindow.x
I am trying to center a div button and its not working here is

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.