如何在下拉菜单上显示白色背景溢出?
我有一个纯粹用 CSS 创建的下拉菜单。我想使用 z-index (我假设)实现溢出,该溢出将在我的菜单上的边框上溢出,给人一种链接和下拉菜单都已连接的印象。
下拉菜单工作正常,但我需要第一个菜单项将其白色背景溢出到下拉菜单上。
如果您转到 http://cssdesk.com/ztK64 并将鼠标悬停在第一个菜单链接上,您将看到我的内容我试图解释。
这是我的代码:
CSS
/*Main nav*/
.main_nav_container{
margin: 10px 0 10px 0;
float:right;
}
ul.main_nav{
margin:0;
z-index:1;
postion:absolute;
}
ul.main_nav li{
margin:0;
display:inline-block;
border-top:solid 1px transparent;
border-left:solid 1px transparent;
border-right:solid 1px transparent;
}
ul.main_nav li a{
font-size:13px;
display:block;
font-weight:bold;
height:25px;
line-height:25px;
padding:0 13px;
text-decoration:none;
color:#1122cc;
border:1px solid transparent;
}
ul.main_nav li a:hover{
text-decoration:underline;
}
ul.main_nav li:hover{
border-top:solid 1px #ccc;
border-left:solid 1px #ccc;
border-right:solid 1px #ccc;
-moz-border-radius: 4px 4px 0 0;
border-radius: 4px 4px 0 0;
-webkit-border-radius: 4px 4px 0 0;
-khtml-border-radius: 4px 4px 0 0;
background: #fff;
}
ul.main_nav li:hover ul{
display:inline;
}
ul.main_nav li ul{
display:none;
z-index:500;
position:absolute;
background: #fff;
margin:0;
padding:0;
border:solid 1px #ccc;
-moz-border-radius: 0 4px 4px 4px;
border-radius: 0 4px 4px 4px;
-webkit-border-radius: 0 4px 4px 4px;
-khtml-border-radius: 0 4px 4px 4px;
}
ul.main_nav li ul li{
display:block;
margin:0;
padding:0;
text-align:left;
}
ul.main_nav li ul li:hover{
text-decoration:underline;
border-top:solid 1px #fff;
border-left:solid 1px #fff;
border-right:solid 1px #fff;
}
ul.main_nav li ul li a{
font-weight:normal;
}
HTML
<div class="main_nav_container">
<ul class="main_nav">
<li>
<a id="hover" href="#">For sale</a>
<ul>
<li><a href="#">Property for sale</a></li>
<li><a href="#">New homes for sale</a></li>
<li><a href="#">Find estate agents</a></li>
</ul>
</li>
<li><a href="#">To rent</a></li>
<li><a href="#">New homes</a></li>
<li><a href="#">House prices</a></li>
<li><a href="#">Blog</a></li>
<li><a href="#">Property advice</a></li>
<li><a href="#">Contact</a></li>
</ul>
</div>
I have a drop down menu created purely with CSS. I would like to implement an overflow using z-index (i presume) that will bleed over a border on my menu to give the impression that both the link and the dropdown menu are joined.
The drop down works correctly but I need the first menu item to overflow it's white background on to the drop down menu.
If you go to http://cssdesk.com/ztK64 and hover over the first menu link you will see what I am attempting to explain.
This is my code:
CSS
/*Main nav*/
.main_nav_container{
margin: 10px 0 10px 0;
float:right;
}
ul.main_nav{
margin:0;
z-index:1;
postion:absolute;
}
ul.main_nav li{
margin:0;
display:inline-block;
border-top:solid 1px transparent;
border-left:solid 1px transparent;
border-right:solid 1px transparent;
}
ul.main_nav li a{
font-size:13px;
display:block;
font-weight:bold;
height:25px;
line-height:25px;
padding:0 13px;
text-decoration:none;
color:#1122cc;
border:1px solid transparent;
}
ul.main_nav li a:hover{
text-decoration:underline;
}
ul.main_nav li:hover{
border-top:solid 1px #ccc;
border-left:solid 1px #ccc;
border-right:solid 1px #ccc;
-moz-border-radius: 4px 4px 0 0;
border-radius: 4px 4px 0 0;
-webkit-border-radius: 4px 4px 0 0;
-khtml-border-radius: 4px 4px 0 0;
background: #fff;
}
ul.main_nav li:hover ul{
display:inline;
}
ul.main_nav li ul{
display:none;
z-index:500;
position:absolute;
background: #fff;
margin:0;
padding:0;
border:solid 1px #ccc;
-moz-border-radius: 0 4px 4px 4px;
border-radius: 0 4px 4px 4px;
-webkit-border-radius: 0 4px 4px 4px;
-khtml-border-radius: 0 4px 4px 4px;
}
ul.main_nav li ul li{
display:block;
margin:0;
padding:0;
text-align:left;
}
ul.main_nav li ul li:hover{
text-decoration:underline;
border-top:solid 1px #fff;
border-left:solid 1px #fff;
border-right:solid 1px #fff;
}
ul.main_nav li ul li a{
font-weight:normal;
}
HTML
<div class="main_nav_container">
<ul class="main_nav">
<li>
<a id="hover" href="#">For sale</a>
<ul>
<li><a href="#">Property for sale</a></li>
<li><a href="#">New homes for sale</a></li>
<li><a href="#">Find estate agents</a></li>
</ul>
</li>
<li><a href="#">To rent</a></li>
<li><a href="#">New homes</a></li>
<li><a href="#">House prices</a></li>
<li><a href="#">Blog</a></li>
<li><a href="#">Property advice</a></li>
<li><a href="#">Contact</a></li>
</ul>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
添加以下 CSS:
您必须在
a
中添加position:relative;
才能使z-index
正常工作。a
的下边框会覆盖ul
的边框。ul
中的边距更改是为了正确定位边框以实现它们连接的效果。Add the following CSS:
You have to have the
position:relative;
in thea
to make thez-index
work correctly. The bottom border of thea
is to cover up the border of theul
. The margin changes in theul
are to position the borders correctly for the effect of them being connected.