简体   繁体   中英

Navigation Bar to Stay on top

I created a nice navigation bar and I want to stay on the top of the page even if the user is scrolling. I've created a separate PHP file for the header named header.php and included it on the main page.

CSS for headermenu

.headerMenu {
background-image: url(../img/background_white.png);
height: 56px;
border-bottom: 0px;
padding-left: auto;
padding-right: auto;
width: 100%;
}

It worked good though but it won't stay on the top when the user scrolls, so I decided to put some additional codes:

.headerMenu {
background-image: url(../img/background_white.png);
height: 56px;
border-bottom: 0px;
padding-left: auto;
padding-right: auto;
width: 100%;

position: fixed;
top: 0;
}

After putting those two codes my navigation bar won't display on the page.
I tried asking some people on the net and they all come up with the position:fixed; top:0; position:fixed; top:0; code. Why it's not working?

HTML

<div class = "headerMenu">
    <div id = "menu">
     <a href = "home.php" />What's New</a>
     <a href = "home.php" /><?php echo $firstname; ?></a>                           
     <a href = "signout_com.php" />Sign Out</a>                                             
    </div>
</div>

Try this :)

.headerMenu {
    position:fixed;
    top:0;
    width:100%;
    background-color:#FF0000;
    background-image:url(../img/background_white.png);
    height:56px;
}

Remove the padding, then remove the self closing tag for your anchors :)

Also make sure you are putting content underneath it :) and then add 56px margin to the top of the content element.

I hope this helps

Nothing wrong in css but in html:

Demo : http://jsfiddle.net/lotusgodkk/xpgzP/99/

HTML:

<div class="headerMenu">
        <div id="menu"> <a href="home.php">What's New</a>
     <a href="home.php">Name</a>  <a href="signout_com.php">Sign Out</a> <!--Incorrect closing tags removed-->
        </div>
    </div>
    <div id="content">content
        <br/>content
        <br/>content
        <br/>content
        <br/>content
        <br/>content
        <br/>content
        <br/>content
        <br/>content
        <br/>content
        <br/>content
        <br/>content
        <br/>content
        <br/>content
        <br/>content
        <br/>content
        <br/>content
        <br/>content
        <br/>content
        <br/>content
        <br/>content
        <br/>content
        <br/>content
        <br/>content
        <br/>content
        <br/>content
        <br/>content
        <br/>content
        <br/>content
        <br/>content
        <br/>
    </div>
    <div id="footer"></div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM