Domanda

Attualmente sto sviluppando un sito e sto cercando di entrare in più codifica CSS, ho fatto il CSS di base per la navigazione fatta.Anche se quello che voglio fare ora è fare i menu secondari, quindi quando tiri su uno dei pulsanti appaiono i menu.

Ecco il mio attuale CSS: Codice HTML:

/*Naviagtion Bar Css */
ul {
    margin: 0;
    padding: 0;
    list-style:none;
}
li {
padding-top:5px;
color: #FFF;
width:120px;
float: left;
margin: 0;
padding: 0;
}
li a {
    display: block;
    width: 120px;
    height: 30px;
    padding-top:20px;
}
#homepage a {
    background-image: url(../images/Button_NavBar_Unselected.png);
    background-repeat: no-repeat;
}
#homepage_current a {
    background-image: url(../images/Button_NavBar_CurrentPage.png);
    background-repeat: no-repeat;
}
#homepage a:hover {
    background-image: url(../images/Button_NavBar_Hover.png);
    background-repeat: no-repeat;
}

#guide a {
    background-image: url(../images/Button_NavBar_Unselected.png);
    background-repeat: no-repeat;
}
#guide_current a {
    background-image: url(../images/Button_NavBar_CurrentPage.png);
    background-repeat: no-repeat;
}
#guide a:hover {
    background-image: url(../images/Button_NavBar_Hover.png);
    background-repeat: no-repeat;
}

#blog a {
    background-image: url(../images/Button_NavBar_Unselected.png);
    background-repeat: no-repeat;
}
#blog_current a {
    background-image: url(../images/Button_NavBar_CurrentPage.png);
    background-repeat: no-repeat;
}
#blog a:hover {
    background-image: url(../images/Button_NavBar_Hover.png);
    background-repeat: no-repeat;
}

#media a {
    background-image: url(../images/Button_NavBar_Unselected.png);
    background-repeat: no-repeat;
}
#media_current a {
    background-image: url(../images/Button_NavBar_CurrentPage.png);
    background-repeat: no-repeat;
}
#media a:hover {
    background-image: url(../images/Button_NavBar_Hover.png);
    background-repeat: no-repeat;
}

#forum a {
    background-image: url(../images/Button_NavBar_Unselected.png);
    background-repeat: no-repeat;
}
#forum_current a {
    background-image: url(../images/Button_NavBar_CurrentPage.png);
    background-repeat: no-repeat;
}
#forum a:hover {
    background-image: url(../images/Button_NavBar_Hover.png);
    background-repeat: no-repeat;
}
#navbar {
    position:relative;
    top:5px;
    float:left;
    margin-top:30px;
    margin-left:45px;
    width:600px;
    height: 50px;
    z-index:-1;
}
.

Codice HTML:

<div id="navbar" style="display: inline-block;">
<ul>
   <li id="homepage_current"><a><strong>Home</strong></a></li>
   <li id="guide"><a><strong>Guide</strong></a>
      <ul>
         <li> Sub Menu 1 </li>
         <li> Sub Menu 2 </li>
         <li> Sub Menu 3 </li>
      </ul>
   </li>
   <li id="blog"><a><strong>Blog</strong></a></li>
   <li id="media"><a><strong>Media</strong></a></li>
   <li id="forum"><a><strong>Forums</strong></a></li>
</ul>
</div>
.

Qualsiasi aiuto sarebbe apprezzato. Ecco un link sulla pagina.

È stato utile?

Soluzione

Il modo per farlo, prima, devi impostare il parente elemento genitore come questo

#navbar>ul>li{position:relative;}
.

Quindi imposta l'elemento figlio per essere sotto il genitore (e renderlo nascosto) (20 px è arbitrario)

#navbar>ul>li>ul{position:absolute;top:20px;left:0px; display:none;}
.

Quindi rendere il sottomenu visibile su Hover

#navbar>ul>li:hover>ul{display:block;}
.

Inoltre, suggerirei di cambiare il tuo stile attuale per Li's a #NAVBAR> UL> LI, poiché il Li CSS influenzerà anche tutti i sottomenu

e fai attenzione all'operatore>, non è supportato in un lotto lotto di vecchio navigatore IE6 e IE5, se questo è importante, utilizzare:

<li id="guide" class="lvl1"><a><strong>Guide</strong></a>
.

e stile con:

li.lvl1{...
.

Altri suggerimenti

Finché non hai qualche problema specifico ti suggerisco uno dei tutorial di maggio che sono là fuori.Ad esempio, è probabilmente il più famoso: Suckerfish !È un inizio perfetto.
O forse Questo potrebbe anche aiutarti.

Infine, ecco un tutorial su come creare un bel css3-dropdown .

Anche i menu CSS-Dropdown sono stati parlato di più volte qui su Stackoverflow.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top