我正在菜单上为我的博客写一篇文章。 我正在尝试创建一个圆形下拉菜单。在所有浏览器上有两个或更多子菜单时,它可以正常工作。但是,如果父菜单只有一个子菜单,则显示在其预定位置下方。
以下是jsfiddle中以下代码的工作副本:http://jsfiddle.net/avdhut/LDmM8/5/
我知道问题出在#menucontainer ul li:hover > ul
选择器中,
它有保证金。但是,如果我删除具有2个或更多子菜单的边缘顶部菜单,则显示在其预期位置之上。
请帮忙,因为我找不到合适的解决方案。
以下是HTML代码:
<div id="menucontainer">
<ul id="hmenu">
<li><a href="http://techisquest.blogspot.com/">Home</a>
<ul>
<li><a href="http://techisquest.blogspot.com/">Test 1</a></li>
<li><a href="http://techisquest.blogspot.com/">Test 2</a></li>
<li><a href="http://techisquest.blogspot.com/">Test 3</a></li>
<li><a href="http://techisquest.blogspot.com/">Test 3</a></li>
</ul>
</li>
<li><a href="http://techisquest.blogspot.com/">About</a>
<ul>
<li><a href="http://techisquest.blogspot.com/">Test 1</a></li>
<li><a href="http://techisquest.blogspot.com/">Test 2</a></li>
</ul>
</li>
<li><a href="http://techisquest.blogspot.com/">Contact Us</a>
<ul>
<li><a href="http://techisquest.blogspot.com/">Test 1</a></li>
</ul>
</li>
<li><a href="http://techisquest.blogspot.com/">Info</a>
<ul>
<li><a href="http://techisquest.blogspot.com/">Test 2</a></li>
<li><a href="http://techisquest.blogspot.com/">Test 3</a></li>
</ul>
</li>
</ul>
</div>
以下是CSS代码:
#menucontainer {
margin: 0px;
padding: 0px;
width: 100%;
height: 90px;
}
/* Following selectors will define the color and the border radius for the menu*/
#menucontainer ul, #menucontainer ul li ul {
list-style: none;
margin: 0px;
padding: 0px;
}
/* Following selector will define the style for individual menu or li tags. The following style gives them a look when the menus are not selected.
note that the position proerty is set to relative and dispaly is inline.
*/
#menucontainer ul li {
list-style: none;
margin: 10px;
padding: 0px;
background-color:#2CDF7B;
position: relative;
display: inline;
text-align: center;
/*Setting the height and width for the menu*/
width: 90px;
cursor:pointer;
height: 90px;
/*Setting the border-radius for the menu
various prefix are added so it is supported in older version of
browsers. For IE supported from IE-9+
IMPORTANT: to keep the border radius height and width same to get circle.
*/
-moz-border-radius: 90px;
-webkit-border-radius: 90px;
-khtml-border-radius: 90px;
border-radius: 90px;
/*Adding the box shadow to the menu*/
box-shadow: 0 0 10px black;
-moz-box-shadow: 0 0 10px black;
-webkit-box-shadow: 0 0 10px black;
float: left;
}
/* Style for the anchor tag defined in the menu.
*/
#menucontainer ul li a {
margin: 10px;
padding: 10px;
background-color:transparent;
display: block;
text-decoration: none;
text-align: center;
font-family:"Times New Roman", "Arabic";
font-size: 18px;
color: #E3E3C0;
}
/* The hover effect is defined using the below selectors
For the opacity is used to create a semi-transperant look as a hover effect
*/
#menucontainer ul li:hover {
list-style: none;
margin: 10px;
padding: 0px;
opacity: 0.7;
background-color:#2CDF7B;
position: relative;
display: block;
width: 90px;
text-align: center;
cursor:pointer;
height: 90px;
/*Setting the border-radius for the menu
various prefix are added so it is supported in older version of
browsers. For IE supported from IE-9+
IMPORTANT: to keep the border radius height and width same to get circle.
*/
-moz-border-radius: 90px;
-webkit-border-radius: 90px;
-khtml-border-radius: 90px;
border-radius: 90px;
-moz-box-shadow: inset 0 0 10px black;
box-shadow: inset 0 0 10px black;
-webkit-box-shadow: inset 0 0 10px black;
}
#menucontainer ul li:hover a {
margin: 10px;
padding: 10px;
background-color:transparent;
display: block;
text-decoration: none;
text-align: center;
font-family:"Times New Roman", "Arabic";
font-size: 18px;
color: white;
}
/*******************************************************/
/*******************************************************/
/*Sub menu*/
/*******************************************************/
#menucontainer ul li > ul {
display : none;
overflow: hidden;
position: relative;
border-bottom: solid 1px;
border: 0px;
height: 0px;
width: 100%;
}
#menucontainer ul li:hover > ul {
z-index: 10;
float: none;
left: -15px;
margin: 40px 10px 10px 10px;
height: auto;
padding: 0px 5px 0px 0px;
display:block;
width: 100px;
}
#menucontainer ul li:hover > ul li, #menucontainer ul li a:hover > ul li {
list-style: none;
margin: 10px;
padding: 0px;
background-color:#2CDF00;
position: relative;
display: inline;
text-align: center;
/*Setting the height and width for the menu*/
width: 90px;
cursor:pointer;
height: 90px;
/*Setting the border-radius for the menu
various prefix are added so it is supported in older version of
browsers. For IE supported from IE-9+
IMPORTANT: to keep the border radius height and width same to get circle.
*/
-moz-border-radius: 90px;
-webkit-border-radius: 90px;
-khtml-border-radius: 90px;
border-radius: 90px;
/*Adding the box shadow to the menu*/
box-shadow: 0 0 10px black;
-moz-box-shadow: 0 0 10px black;
-webkit-box-shadow: 0 0 10px black;
float: left;
}
/*******************************************************/
#menucontainer ul li:hover > ul li:after, #menucontainer ul li a:hover > ul li:after {
content:" ";
border: solid transparent;
margin: 0px;
padding: 0px;
position: absolute;
pointer-events: none;
border-color: rgba(44, 223, 123, 0);
border-top-color: #2CDF00;
top: 98%;
left: 50%;
margin-left: -10px;
border-width:10px;
}
#menucontainer ul li:hover > ul li:before, #menucontainer ul li a:hover > ul li:before {
content:" ";
border: solid transparent;
margin: 0px;
padding: 0px;
position: absolute;
pointer-events: none;
border-color: rgba(44, 223, 123, 0);
border-bottom-color: #2CDF00;
bottom: 98%;
left: 50%;
margin-left: -10px;
border-width:10px;
}
/*******************************************************/
答案 0 :(得分:2)
对css进行了一些更改,你就完成了: -
#menucontainer ul li > ul {
display : none;
overflow: hidden;
position: absolute; //implement absolute
border-bottom: solid 1px;
border: 0px;
height: 0px;
width: 100%;
top:90px; //add top
}
#menucontainer ul li:hover > ul {
z-index: 10;
float: none;
left: -15px;
margin: 5px; //change it to this
height: auto;
padding: 0px 5px 0px 0px;
display:block;
width: 100px;
}
工作小提琴: - http://jsfiddle.net/LDmM8/7/
答案 1 :(得分:1)
这与您在该下拉菜单中只有1个项目的事实无关。您可以尝试添加更多内容并查看它仍在发生。真正的原因是&#34;联系我们&#34;按钮是两行,而不是像其他按钮一样。
通过为anchors
设置固定高度来解决问题。
#menucontainer ul li a {
height:33px;
}