Apparition du background dans le menu déroulant

Résolu/Fermé
agencesyscom Messages postés 20 Date d'inscription mercredi 19 juin 2013 Statut Membre Dernière intervention 25 mars 2014 - 26 déc. 2013 à 15:03
animostab Messages postés 2829 Date d'inscription jeudi 10 mars 2005 Statut Membre Dernière intervention 11 novembre 2019 - 28 déc. 2013 à 13:11
Bonjour à tous,
j'ai un petit souci. J'ai créé un menu déroulant à plusieurs niveaux (2 au total avec le bouton principal). Le bouton principal possède un fond en images (une pour a: et l'autre pour a:hover), et les niveaux inférieurs également (juste pour a:). Au moment de passer au second niveau, le background a:hover du bouton principal apparaît alors qu'il est censé être désactivé pour les 2 niveaux inférieurs du menu déroulant. Je ne parviens pas à trouver où est l'erreur, peut-être que quelqu'un peut m'aider ??? J'espère avoir été claire parce que ce n'est pas simple à expliquer...

voici le code html du menu en question :
<ul id="menu">
<li><a href="">Nos Métiers</a>
<ul>
<li><a href="">Etudes d'exécution en signalisation ferroviaire</a></li>
<li><a href="">Ingénierie en signalisation ferroviaire</a></li>
<li><a href="">Autres</a>
<ul>
<li><a href="">Assistance aux appels d'offres</a></li>
<li><a href="">Formations</a></li>
<li><a href="">Travaux de DAO</a></li>
<li><a href="">Travaux de calques</a></li>
</ul>
</li>
</ul>
</li>
</ul>

Le code CSS :
#menu
{
width: 920px;
margin: 0;
padding: 0;
list-style: none;
text-align:center;
}

#menu li
{
float: left;
padding: 0 0 0px 0;
position: relative;
line-height: 0;
}

#menu a
{
float: left;
width:184px;
height: 60px;
padding-top:0px;
padding-left:0px;
padding-bottom:0px;
padding-right:0px;
color: #fff;
text-transform: uppercase;
text-decoration: none;
text-shadow: 0 1px 0 #CB760A;
background-image:url(../img-index/btn-fond.png);
background-repeat:no-repeat;
background-position:center;
font-family:Eurostile;
font-size: 16px;
line-height: 55px;
font-weight: bold;
}

#menu li:hover > a
{
color: #fff;
background-image:url(../img-index/btn-hover.png);
background-repeat:no-repeat;
background-position:center;
text-shadow: 0 1px 0 #02002B;
}

*html #menu li a:hover /* IE6 */
{
color: #fff;
background-image:url(../img-index/btn-hover.png);
background-repeat:no-repeat;
background-position:center;
text-shadow: 0 1px 0 #02002B;
}

#menu li:hover > ul
{
display: block;
}

/* Sub-menu */

#menu ul
{
list-style: none;
margin: 0;
padding: 0;
display: none;
position: absolute;
top: 60px;
left: 15px;
z-index: 99999;
background:url(../img-index/img-sous-rub-fond.png);
background-repeat:repeat-y;
background-position:center;
-moz-box-shadow: 0 0 2px rgba(255,255,255,.5);
-webkit-box-shadow: 0 0 2px rgba(255,255,255,.5);
box-shadow: 0 0 2px rgba(255,255,255,.5);
-moz-border-radius: 5px;
border-radius: 5px;
}

#menu ul ul
{
top: 0;
left: 220px;
}

#menu ul li
{
float: none;
margin: 0;
padding: 0;
display: block;
-moz-box-shadow: 0 1px 0 #333333, 0 2px 0 #555555;
-webkit-box-shadow: 0 1px 0 #333333, 0 2px 0 #555555;
box-shadow: 0 1px 0 #333333, 0 2px 0 #555555;
}

#menu ul li:last-child
{
-moz-box-shadow: none;
-webkit-box-shadow: none;
box-shadow: none;
}

#menu ul a
{
padding: 10px;
height: 10px;
width:200px;
height: auto;
line-height: 1;
display: block;
white-space: normal;
float: none;
text-transform: none;
background-image:none;
text-shadow: 0 1px 0 #333333;
font-weight: normal;
text-align:left;
font-size: 14px;
}

*html #menu ul a /* IE6 */
{
height: 10px;
background-image:none;
}

*:first-child+html #menu ul a /* IE7 */
{
height: 10px;
background-image:none;
}

#menu ul a:hover
{
background:#F7981F;
background: -moz-linear-gradient(#ffB34F, #F7981F);
background: -webkit-gradient(linear, left top, left bottom, from(#ffB34F), to(#F7981F));
background: -webkit-linear-gradient(#ffB34F, #F7981F);
background: -o-linear-gradient(#ffB34F, #F7981F);
background: -ms-linear-gradient(#ffB34F, #F7981F);
background: linear-gradient(#ffB34F, #F7981F);
text-shadow: 0 1px 0 #CB760A;
font-weight: normal;
}

#menu ul li:first-child > a
{
-moz-border-radius: 5px 5px 0 0;
border-radius: 5px 5px 0 0;
}

#menu ul li:first-child > a:after
{
content: '';
position: absolute;
left: 30px;
top: -8px;
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-bottom: 8px solid #444;
}

#menu ul ul li:first-child a:after
{
left: -8px;
top: 12px;
width: 0;
height: 0;
border-left: 0;
border-bottom: 5px solid transparent;
border-top: 5px solid transparent;
border-right: 8px solid #444;
}

#menu ul li:first-child a:hover:after
{
border-bottom-color: #fFB34F;
}

#menu ul ul li:first-child a:hover:after
{
border-right-color: #fFB34F;
border-bottom-color: transparent;
}


#menu ul li:last-child > a
{
-moz-border-radius: 0 0 5px 5px;
border-radius: 0 0 5px 5px;
}

#menu:after
{
visibility: hidden;
display: block;
font-size: 0;
content: " ";
clear: both;
height: 0;
}
A voir également:

4 réponses

animostab Messages postés 2829 Date d'inscription jeudi 10 mars 2005 Statut Membre Dernière intervention 11 novembre 2019 738
Modifié par animostab le 26/12/2013 à 21:12
Salut
Un div (ou balise html) enfant hérite des propriétés css de son parent meme a plusieurs niveau
donc ici il hérite du background-image

il faut donc le déshériter en lui appliquant un background-image:none;

#menu ul ul
{
top: 0;
left: 220px;
background-image:none;
}

Un petit merci vaut mieux qu'une grande ignorance
1
agencesyscom Messages postés 20 Date d'inscription mercredi 19 juin 2013 Statut Membre Dernière intervention 25 mars 2014
27 déc. 2013 à 14:06
Merci pour ta réponse animostab !

Malheureusement, ça ne fonctionne pas, ceci me supprime le fond du dernier niveau.
Pour que tu comprennes mieux d'où vient le problème, j'ai fait un imp écran que tu peux voir à l'adresse suivante :
http://syscom.net.pagesperso-orange.fr/menu.jpg
Le souci vient au niveau de la rubrique "autre" où le fond bleu apparait lorsque je vais vers le dernier niveau de rubrique.

Merci pour ton aide et bon après-midi :)
0
animostab Messages postés 2829 Date d'inscription jeudi 10 mars 2005 Statut Membre Dernière intervention 11 novembre 2019 738
27 déc. 2013 à 15:17
Ok je n'avais pas compris

voila ce que tu dois faire

au lieu de

#menu li:hover > a

tu mets

#menu a:hover

voila
mais bon personnellement je trouve ton css très compliqué pour un simple menu à 2 étages



0
agencesyscom Messages postés 20 Date d'inscription mercredi 19 juin 2013 Statut Membre Dernière intervention 25 mars 2014
28 déc. 2013 à 12:31
Super ça marche !

Merci à toi animostab :)
0
animostab Messages postés 2829 Date d'inscription jeudi 10 mars 2005 Statut Membre Dernière intervention 11 novembre 2019 738
28 déc. 2013 à 13:11
ok tu peux mettre en résolu
0