Is it possible to display a sub-list beside it's parent using only css and no fixed width?
I'm trying to implement a navigation menu in css. I managed to display the first submenu under it's parent. But when it come to the submenu of the submenu, I only manged to put it beside it's parent with a fixed offset. But since the offset can differ depending on the width of the parent, and the width of the parent change depending of the browser used, that solution does not work.
here is my css
.main-nav{
position: fixed;
top: 0;
left: 0;
right: 0;
height: 0;
text-align: center;
}
.nav-centered {
display: inline-block;
text-align: left;
margin:0;
padding:0;
z-index:10;
}
.nav-main-menu {
list-style-type: none;
background-color:#91a056;
margin:0;
padding:0;
height:25px
}
.nav-main-menu li {
display: inline;
text-align: center;
float:left;
position:relative;
}
.nav-main-menu li a img {
padding-bottom:0px;
color: #fff;
background-color: #91a056;
}
.nav-main-menu li a:hover {
background-color: #bbc888;
}
.nav-main-menu li li a:hover, .nav-main-menu li li span:hover, .nav-main-menu li li span:hover {
background-color: #bbc888;
}
.nav-main-menu li:hover ul {
display:block;
float:left;
}
.nav-main-menu li li, .nav-main-menu li li li {
display:block;
text-align:left;
width:100%;
border: 3px ridge #91a056;
}
.nav-main-menu li ul, .nav-main-menu li li ul, .nav-main-menu li:hover li ul {
display:none;
position:absolute;
}
.nav-main-menu li li:hover ul {
display:block;
float:left;
top:0px;
left:176px; /* I want to get rid of this fixed offset */
}
.nav-main-menu li li li a, .nav-main-menu li li a, .nav-main-menu li li span {
display:block;
text-align: left;
white-space: nowrap;
font-size:100%;
color: #FFF;
padding: 0 1em;
background-color: #91a056;
}
.nav-main-menu li li a span{
padding: 0;
}
.nav-main-menu li a {
margin-left:auto;
margin-right:auto;
font-size:120%;
text-decoration: none;
padding: 0 1em;
color: #fff;
background-color: #91a056;
}
I want to get rid of the .nav-main-menu li li:hover ul
left offset.
And here is the revelant part of my html code
<div xmlns="http://www.w3.org/1999/xhtml" class="main-nav">
<div class="nav-centered">
<ul class="nav-main-menu">
<li><a href="/" ><span>Acceuil</span></a></li>
<li><a href="/?_=/page/regle" ><span>Regles de jeu</span></a>
<ul>
<li><span>Les personnages</span>
<ul>
<li><a href="/?_=/page/regle/commencer" ><span>Se creer un personnage</span></a></li>
<li><a href="/?_=/page/regle/race" ><span>Les Races</span></a></li>
<li><a href="/?_=/page/regle/alignement" ><span>Les Alignements</span></a></li>
<li><a href="/?_=/page/regle/entrainement" ><span>Les Entrainements</span></a></li>
<li><a href="/?_=/page/regle/conpetence" ><span>Les Competences</span></a></li>
<li><a href="/?_=/page/regle/handicape" ><span>Les Handicapes</span></a></li>
<li><a href="/?_=/page/regle/dieu" ><span>Les Dieux</span></a></li>
<li><a href="/?_=/page/regle/doamine" ><span>Les Domaines</span></a></li>
<li><a href="/?_=/page/regle/sort" ><span>Les Sorts</span></a></li>
<li><a href="/?_=/page/regle/profile" ><span>Les Profiles</span></a></li>
<li><a href="/?_=/page/regle/terrictoire" ><span>Les Terrictoires</span></a></li>
<li><a href="/?_=/page/regle/prestige" ><span>Les Prestiges</span></a></li>
</ul>
</li>
<li><span>Les reglements</span>
<ul>
<li><a href="/?_=/page/regle/combat" ><span>Les Combats</span></a></li>
<li><a href="/?_=/page/regle/etatAlterer" ><span>Les Etats Alteres</span></a></li>
</ul>
</li>
<li><span>L'univers</span>
<ul>
<li><a href="/?_=/page/regle/seigneurie" ><span>Les Seigneuries</span></a></li>
<li><a href="/?_=/page/regle/groupe" ><span>Les Groupes</span></a></li>
</ul>
</li>
</ul>
</li>
<li class="nav-login"><a href="/?_=/login" ><span>Inconnue</span></a>
<ul>
<li><a href="/?_=/login" ><span>Se connecter</span></a></li>
</ul>
</li>
<li><a href="/?_=/page/info" ><span>Qui sommes-nous?</span></a></li>
<li><a href="/?_=/forum" ><span>Forum</span></a></li>
<li><a href="https://www.facebook.com/" ><img alt="Page facebook" src="/img/icon-facebook.gif" style="max-width:19.0px;max-height:19.0px;" /></a></li>
</ul>
</div>
</div>