Results 1 to 4 of 4

Thread: #nav won't stay on top

  1. #1
    Join Date
    Oct 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default #nav won't stay on top

    This is a simple example to illustrate my problem:

    Code:
    <html>
    	<head>
    		<style type="text/css">
    			#container {position: absolute; left: 50%; width: 400px; margin-left: -200px; border: 1px solid orange;}
    			#content {margin-top: 75px;}
    			#nav {position: fixed; top: 0; width: 400px; border-top: 1px solid orange; border-bottom: 1px solid orange;}
    		</style>
    	</head>
    
    	<body>
    		<div id="container">
    			<div id="nav">
    				<a href="">home</a>
    				<a href="">about</a>
    				<a href="">contact</a>
    				<a href="">products</a>
    				<a href="">links</a>
    			</div>
    
    			<div id="content">
    				<h1>This is content!</h1>
    				<p>Accomplishing this is somewhat challenging because of the way that elements are centered horizontally in CSS.  
    				A number of centering options exist.  I'm going to use what's known as the negative-margin approach to horizontal 
    				centering.  Although it's not the preferred method according to CSS best practices, it is the most supported 
    				across browsers.</p>
    			</div>
    
    			<p style="margin-top: 1000px;">Hello</p>
    		</div>
    	</body>
    </html>
    When I run this in MSIE it works great, just like I want it to - the #nav section stays on the top of the PAGE when you scroll down. In Firefox, however, the #nav sections stays on top of the SCREEN when you scroll down (virtually scrolling down with you). Why does that happen and how can I fix that? Thank you.

    peace,
    mark
    Last edited by markdlv77; 12-15-2007 at 07:16 PM. Reason: code wasn't showing right

  2. #2
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    #nav {position: fixed;
    As such...

    Quote Originally Posted by W3Schools
    An element with position: fixed is positioned at the specified coordinates relative to the browser window. The element's position is specified with the "left", "top", "right", and "bottom" properties. The element remains at that position regardless of scrolling. Works in IE7 (strict mode).

    An element with position: absolute is positioned at the specified coordinates relative to its containing block. The element's position is specified with the "left", "top", "right", and "bottom" properties
    Try using absolute, instead of fixed.
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  3. #3
    Join Date
    Oct 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Ha!

    Oh my gosh I can't believe I didn't catch that... thanx a lot - that sure solved it.

    peace,
    mark

  4. #4
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    You are quite welcome
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •