Click here to Skip to main content
15,889,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i made a html 5 nav with nav tag and put a list in there like below.
1) how can i make it horizontal with css?
2) i want a performance like: user scrolls down the page and my nav sticks to the
screen top so user always see it and when scrolls up, it turns back in its original
place in bottom of header tag <header>

here's html code:

XML
<header>
        <nav>
            <ul>
                <li><a href="#">Home</a></li>
                <li><a href="#">Services</a>
                    <ul>
                        <li><a href="#">Download</a></li>
                        <li><a href="#">Upload</a></li>
                    </ul>
                </li>
                <li><a href="#">Products</a>
                    <ul>
                        <li><a href="#">Utilities</a></li>
                        <li><a href="#">Web browser</a></li>
                        <li><a href="#">Anti Virus</a></li>
                    </ul>
                </li>
                <li><a href="#">News</a>
                    <ul>
                        <li><a href="#">Feeds</a></li>
                    </ul>
                </li>
                <li><a href="#">About Us</a></li>
            </ul>
        </nav>
    </header>


css for header:

C#
header {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100px;

    background-image: url("texture.jpg");
    background-repeat: repeat-x;
}
Posted
Updated 9-Sep-13 5:31am
v2
Comments
Bala Selvanayagam 9-Sep-13 12:31pm    
I am not sure about the nav tag

have a look at http://www.quackit.com/css/codes/css_floating_menu.cfm

1 solution

i solved it myself

CSS
header {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100px;

    background-image: url("texture.jpg");
    background-repeat: repeat-x;
}
nav{
    position: absolute;
    left: 440px;

    margin-top: 49px;
}
nav ul{
    position: relative;
    display: -webkit-box;

    border-bottom-color: #000;
    list-style: none;
    border: 0;
}
nav ul li{
    width: 70px;
    height: 35px;
    display: block;

    background-color: #fff;
    border-right-style: solid;
    border-right-width: 1px;
    text-align: center;
}
nav ul li ul{
    display: none;
    height: 0;
    =webkit-transition: height 1s;
}
nav ul li:hover{
    background-color: #5ea2d8;
}
nav ul li:hover ul{
    position: absolute;
    height: 100%;
    display: block;

    opacity: 100%;
}
nav ul li:hover ul li{
    width: 100px;
    position: relative;
    top: 16px;
    left: -55px;

    border-right-style: none;
    border-top-style: solid;
    border-top-width: 1px;
}
nav ul li:hover ul li.last{
    border-bottom-style: solid;
    border-bottom-width: 1px;
}
nav a{
    position: relative;
    top: 8px;
    text-decoration: none;
    color: #000;
}
nav a:hover{
    color: #fff
}

and for scroll functionality:

C#
var isFixed = false;
$(window).scroll(function() {
    var nav = $('#nav');
    var scrollTop = $(window).scrollTop();
    var shouldBeFixed = scrollTop > 100;
    if(shouldBeFixed){

    }
    if (shouldBeFixed && !isFixed) {
         nav.css({position: 'fixed', top: 0,'margin-top': '0'});
         isFixed = true;
    }
    else if (!shouldBeFixed && isFixed){
         nav.css({position: 'relative','margin-top': '30px'});
         isFixed = false;
    }
});
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900