我的下拉菜单具有绝对位置,我想将下拉菜单居中到其各自的 li。我不想静态设置边距,因为它也会影响其他菜单。HTML
<div class="top_nav">
<!--naviagation top Begins-->
<ul>
<li id="active">
<a href="#" id="active"><img src="images/home.png" />home</a>
<!-- <div class="DDmenu" id="hmedd" style="display:none">
<ul>
<li><a href="#">Dummy1</a></li>
<li><a href="#">Dummy2</a></li>
<li><a href="#">Dummy3</a></li>
</ul>
</div>-->
<div class="clear"></div>
<div class="current_menu"></div>
</li>
<li id="abt" onmouseover="showmenu('abtdd');" onmouseout="hidemenu('abtdd');" >
<a href="#">about us</a>
<div class="DDmenu" id="abtdd" style="display:none">
<ul>
<li><a href="#">Dummy1</a></li>
<li><a href="#">Dummy2</a></li>
<li><a href="#">Dummy3</a></li>
</ul>
</div>
</li>
<li id="invent" onmouseover="showmenu('inventdd');" onmouseout="hidemenu('inventdd');">
<a href="#">inventions</a>
<div class="DDmenu" id="inventdd" style="display:none">
<ul>
<li><a href="#">Dummy Invent1</a></li>
<li><a href="#">Dummy Invent2</a></li>
<li><a href="#">Dummy Invent3</a></li>
</ul>
</div>
</li>
<li id="archi" onmouseover="showmenu('archidd');" onmouseout="hidemenu('archidd');">
<a href="#">architectural</a>
<div class="DDmenu" id="archidd" style="display:none">
<ul>
<li><a href="#">Dummy Architecture1</a></li>
<li><a href="#">Dummy Architecture2</a></li>
<li><a href="#">Dummy Architecture3</a></li>
</ul>
</div>
</li>
<li id="artli" onmouseover="showmenu('artlidd');" onmouseout="hidemenu('artlidd');">
<a href="#">art pieces</a>
<div class="DDmenu" id="artlidd" style="display:none">
<ul>
<li><a href="#">Dummy art1</a></li>
<li><a href="#">Dummy art2</a></li>
<li><a href="#">Dummy art3</a></li>
</ul>
</div>
</li>
<li id="caravanli" onmouseover="showmenu('caravanlidd');" onmouseout="hidemenu('caravanlidd');">
<a href="#">caravan</a>
<div class="DDmenu" id="caravanlidd" style="display:none">
<ul>
<li><a href="#">Dummy caravan1</a></li>
<li><a href="#">Dummy caravan2</a></li>
<li><a href="#">Dummy caravan3</a></li>
</ul>
</div>
</li>
<li id="tab">
<a href="#">tables</a>
</li>
</ul>
<!--naviagation top Ends-->
</div>
CSS:
.top_nav
{
width:100%;
height:30px;
/*margin-left:130px;*/
}
.top_nav ul
{
padding:0;
margin:0 0 0 68px;
}
.top_nav ul li#active
{
float:left;
position:relative;
padding:5px 0 0 0;
background: #c2cca2;
margin:0 8px;
color:#000;
list-style:none;
}
.top_nav ul li
{
float:left;
position:relative;
padding:12px 0 7px 35px; /*added padding top+5 to add space between bg and text*/
margin:0 8px;
list-style:none;
}
.top_nav ul li a
{
text-decoration:none;
text-transform:capitalize;
color:#fff;
font-size:14px;
font-weight:bold;
padding-right:6px;
vertical-align:baseline;
}
.top_nav ul li:hover a{color:#000;}
.top_nav ul li ul li a{color:#FFF!important;}
.top_nav ul li ul li:hover a{color:#000!important;}
.top_nav ul li a#active
{
text-decoration:none;
text-transform:capitalize;
color:#000;
font-size:14px;
font-weight:bold;
padding-right:6px;
vertical-align:baseline;
}
/*.top_nav ul li:hover
{
/*background:#c2cca2;
background:url(../images/menu_bg.png) left top repeat-y;
}*/
.top_nav ul li#abt
{
background:#c2cca2;
}
.top_nav ul li#invent
{
background:#c2cca2;
height:19px;
}
.top_nav ul li#archi
{
background:#c2cca2;
height:19px;
}
.top_nav ul li#artli
{
background:url(../images/art.png) 5px 5px no-repeat;
height:19px;
}
.top_nav ul li#caravanli
{
background:#c2cca2;
height:19px;
}
.top_nav ul li#tab
{
background:#c2cca2;
height:19px;
}
.top_nav ul li#abt:hover
{
background:#c2cca2;
color:#000 !important;
height:19px;
}
.top_nav ul li#abt:hover>a:hover{color:inherit;}
.top_nav ul li:hover
{
color:#000;
}
.top_nav ul li#invent:hover
{
background:#c2cca2;
color:#000;
}
.top_nav ul li#archi:hover
{
background:#c2cca2;
color:#000;
}
.top_nav ul li#artli:hover
{
background:#c2cca2;
color:#000;
}
.top_nav ul li#caravanli:hover
{
background:#c2cca2;
color:#000;
}
.top_nav ul li#tab:hover
{
/*background:#c2cca2;*/
background:#c2cca2;
color:#000;
}
/*.top_nav ul li a:hover
{
background:#c2cca2;
padding:16px 6px 2px 0;
padding:16px 6px 0 0\0/;
}*/
.top_nav ul li img
{
/*float:left;
position:relative;*/
padding:0 4px 0 5px;
}
JS
function showmenu(idm)
{
document.getElementById(idm).style.display='';
}
function hidemenu(idmn)
{
document.getElementById(idmn).style.display='none';
}
任何建议将不胜感激。