[英]css dropdown menu alignment
I have created a dropdown menu using CSS based, however when you hover over the parent list item, the unordered list displays anchored to the left of the parent item. 我已经使用基于CSS的下拉菜单创建了一个菜单,但是当您将鼠标悬停在父列表项上时,无序列表将显示在父项的左侧。 I would like it to be central to them, but I cant figure out how.
我希望它对他们很重要,但是我不知道怎么做。
http://jsfiddle.net/jspring/LtVaq/ http://jsfiddle.net/jspring/LtVaq/
Html: HTML:
<ul class="ulRight">
<li><a href="#">Settings</a>
<ul>
<li><a href="#">This Is</a></li>
<li><a href="#">Sub Menu</a></li>
<li><a href="#">One</a></li>
</ul>
</li>
<li><a href="#">Your Account</a>
<ul>
<li><a href="#">Sub Menu</a></li>
<li><a href="#">Two</a></li>
<li><a href="#">Now!</a></li>
</ul>
</li>
.ulRight {
/*To float UL List to right*/
list-style:none outside none !important;
position:absolute;
right:10px;
top:0px;
display:inline-table;
z-index:1000;
}
.ulRight ul:after {
content:"";
clear:both;
display:block;
}
.ulRight > li {
display:inline;
color:#BBBBBB;
width:auto;
}
.ulRight li > ul {
vertical-align:middle;
z-index:1001;
display:none;
position:relative;
margin:auto;
top:40px;
width:inherit;
}
.ulRight li:hover > ul {
display:block;
}
.ulRight > li {
margin:0 5px 0 5px;
}
.ulRight > li {
float:left;
}
.ulRight > li:hover {
background:#FFF;
border:1px solid #CCCCCC;
}
.ulRight a {
text-decoration:none;
font-weight:normal;
display:block;
padding:10px;
}
.ulRight li:hover a {
font-weight:bold;
color:#80B5E9;
text-align:center;
}
.ulRight li > ul {
background:#FFF;
border-radius:0px;
padding:0px;
position:absolute;
box-shadow:0px 0px 9px rgba(0, 0, 0, 0.15);
border:1px solid #CCCCCC;
}
.ulRight li > ul > li {
list-style:none;
float:none;
border-top:1px solid #CCCCCC;
border-bottom:1px solid #CCCCCC;
position:relative;
}
.ulRight li > ul a {
}
.ulRight li > ul a:hover {
color:#FFF;
background:#303030;
}
Any help would be much appreciated! 任何帮助将非常感激!
change to a relative position 转到相对位置
.ulRight li > ul{
position:relative;
top:0;
}
The main problem i see is that your parent list's width is not consistent. 我看到的主要问题是您的父列表的宽度不一致。
.ulRight li >ul{
position:realative; // this position makes the child position realative to your parent list which is left justified....
}
The quickest and easiest is the apply fix width. 最快和最容易的是应用修复宽度。 This way your parent and child list are all the same width.
这样,您的父级和子级列表的宽度都相同。
.ulRight > li {
display:inline;
color:#BBBBBB;
width:auto; // Change this to 110px or what ever you see fit
}
if you don't like this solution you will need to use javascript to set up parameters...(to my knowledge anyway) 如果您不喜欢此解决方案,则需要使用javascript设置参数...(无论如何,据我所知)
hope this helps 希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.