• first
  • Clever Geek Handbook

    CSS - Scrolling content over a fixed positioned element?

    HTML:

    <div id="container">
        <ul>
            <li><a href="#first">first</a></li>
            <li><a href="#second">second</a></li>
            <li><a href="#third">third</a></li>
        </ul>
        <div id="somecontainer">
            <div id="first">
            </div>
            <div id="second">
            </div>
            <div id="third">
            </div>
        </div>
    </div>
    
          

    DEMO: http://jsfiddle.net/JRnDz/

    Problem: When you click on the "second" link, the page should navigate to the div with the id "second". However, it does not display the entire div, but only part of it (150px-50px = 100px). The top of the div is cut off.

    Question: How can I display the entire div after clicking the "second" link?

    WHAT I AM EXCLUDING: Adding relative positioning and vertex: 50px to the container:

    #container {
      position: relative;
      top: 50px;
    }
    
          

    +3
    css scroll position css-position


    RhymeGuy 12 Feb 13 at 12:24
    source to share


    4 answers


    The solution written by @ ipsnow72 is more obvious.

    If you prefer, you can use the jquery plugin ScrollTo and use the offset parameter. http://demos.flesler.com/jquery/scrollTo/



    $(...).scrollTo( '#yourelement', {offset:-50} );
    
          

    +2


    Fez Vrasta 12 Feb 13 at 12:51
    source to share


    It depends on using this code, but if you add

    #someconteiner div{
        padding-top:50px;
        margin-bottom:-50px;
        position:relative;
        display:block;
    }
    
          



    and play around a bit with z-indices: http://jsfiddle.net/JRnDz/2/

    +2


    Jan 12 Feb 13 at 13:35
    source to share


    You can try this:

    <div id="container">
    <ul>
        <li><a href="#first">first</a></li>
        <li><a href="#secondJump">second</a></li>
        <li><a href="#third">third</a></li>
    </ul>
    <div id="someconteiner">
        <div id="first">
        </div>
        <a name="secondJump"></a>
        <div id="second">
        </div>
        <div id="third">
        </div>
    </div>
    </div>
    
          

    Place the location you want to jump to as an anchor above the div you want to jump to.

    Obviously, you will do the same for 1st and 3rd.

    EDIT: Try to just remove the fixed position from your ul

    +1


    jpsnow72 12 Feb 13 at 12:34
    source to share


    How about this:

    <div id="container">
    <ul>
        <li><a href="#first">first</a></li>
        <li><a href="#secondAnchor">second</a></li>
        <li><a href="#third">third</a></li>
    </ul>
    <div id="someconteiner">
        <div id="first">
        </div>
        <a name="secondAnchor" style="padding-top: 50px; margin-top: -50px;"></a>
        <div id="second">
        </div>
        <div id="third">
        </div>
    </div>
    </div>
    
          

    See: Fixed navbar position hides anchors

    0


    jpsnow72 12 Feb At 13:02
    source to share






    More articles:

    • add new user to James - java
    • WPF hits rectangular region test - wpf
    • How to handle MouseMove events in C # faster - c #
    • DB2 sequence value using Java - java
    • Convert byte array to pdf with C # code - pdf
    • Conditions against wait / notify objects - java
    • How to use CSS: not () correctly? - html
    • Nginx redirect merge_slashes - redirect
    • ObjectContext.CreateDatabase () creates additional tables that are not part of the .edmx model - c #
    • The ternary operator should not be used on the same line in Node.js. What for? - standards

    All Articles

    Daily Blog | 2020

    Green Geek Media (GGM)
    1298 Despard Street
    GA 30344 East Point, USA
    404-763-3837