Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
159 views
in Technique[技术] by (71.8m points)

How do I add a horizontal submenu? can't figure it out, added html and css

Hey I would like to have a dropdown sub- menu in the same style, I know it's simple but I'm still new to making websites and I can't figure it out by myself.

here's my HTML file:

<nav>
        <ul>
            <li><a href="./index.html"><span class ="s2">Startpagina</span></a></li>
            <li><a href="./aanwinsten.html">Aanwinsten</a></li>
            <li><a href="./catalogus.html">Catalogus</a></li>
                <ul class="sub">
                    <li><a href="#">Pages</a></li>
                    <li><a href="#">Archives</a></li>
                    <li><a href="#">New Posts</a></li>
                </ul>
            <li><a href="./uitlening.html">Uitlening</a></li>
            <li><a href="./reservatie.html">Reservatie</a></li>
            <li><a href="./suggestie.html">Suggestie</a></li>
            <li><a href="./contact.html">Contact</a></li>
        </ul>
    </nav>

and this is my CSS file:

  nav li
{
    display: inline;
    padding-right: 20px;

}
nav {
    text-align: center;
    margin: -20px 0px 0px 0px;

}
nav ul{
    background-color: rgba(126, 4, 0, 0.79);
    border: 1px solid black;


}
nav ul li{
    display: inline;

}
nav ul li a{
    padding-left: 1em;
    padding-right: 1em;
    font-size: 12px;
    font-family: Arial, Helvetica, sans-serif;
    text-decoration: none;
    color: lightgray;
}
nav ul li a:hover{
    color: #999999;

}

EDIT: I've edited the /li problem and I've added this to my CSS:

nav ul ul{display: none; position: relative;}
nav li ul li{float:none;display: inline-block; }
nav ul li:hover ul  {display: inline-block;}

which gives this when I hoover over it: http://gyazo.com/e095151ebf644b4b44c7556193328163

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You closed the li that will hold the submenu ul too early.

Try working with this:

<nav>
        <ul>
            <li><a href="./index.html"><span class ="s2">Startpagina</span></a></li>
            <li><a href="./aanwinsten.html">Aanwinsten</a></li>
            <li><a href="./catalogus.html">Catalogus</a>
                <ul class="sub">
                    <li><a href="#">Pages</a></li>
                    <li><a href="#">Archives</a></li>
                    <li><a href="#">New Posts</a></li>
                </ul>
            </li> **<! - See the difference?-->**
            <li><a href="./uitlening.html">Uitlening</a></li>
            <li><a href="./reservatie.html">Reservatie</a></li>
            <li><a href="./suggestie.html">Suggestie</a></li>
            <li><a href="./contact.html">Contact</a></li>
        </ul>
    </nav>

JSFiddle


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...