【发布时间】:2014-04-24 15:03:56
【问题描述】:
我刚刚创建了一个带有下拉菜单的按钮,您可以查看演示here。
在演示中,我为shopping-cart-wrapper 元素添加了黑色背景,以便您查看问题所在。
问题是当您将鼠标悬停在按钮上时,您可以将鼠标保持在黑色背景上,并且下拉菜单仍然可见。
我只希望当您将鼠标悬停在按钮上或将鼠标停留在下拉菜单上时下拉菜单可见。
这是我的代码:
HTML:
<div class="shopping-cart-wrapper">
<a class="shopping-cart" href="#" alt="my-shopping-cart">My Shopping Cart (0)</a>
<div class="shopping-cart-dropdown">
<div class="empty-cart"><span>Your shopping cart is empty</span></div>
</div>
</div>
CSS:
.shopping-cart-wrapper:hover .shopping-cart-dropdown {
opacity: 1;
display: block;
}
.shopping-cart-wrapper {
display: inline-block;
background: #000;
margin-top: 5px;
margin-left: 15px;
}
.shopping-cart {
border: 1px solid #d3d3d3;
color: #656565;
padding-right: 10px;
padding-top: 8px; padding-bottom: 8px;
padding-left: 40px;
font-weight: bold;
display: inline-block;
font-size: 13px;
text-align: right;
text-decoration: none;
box-shadow: 0px 1px 0px #f2f2f2;
background: #f8f8f8 url("http://placehold.it/32x32") no-repeat 0 0 ;
position: relative;
}
.shopping-cart:hover {
background: #fff url("images/cart-sprite.png") no-repeat 0 -29px ;
color: #202020;
border: 1px solid #c6c6c6;
box-shadow: 0px 1px 0px #e5e5e5;
}
.shopping-cart-dropdown {
opacity: 0;
display: none;
border: 1px solid #d3d3d3;
padding-bottom: 80px;
position: relative;
right: 49px;
width: 247px;
background: #f6f6f6;
font-size: 12px;
font-weight: bold;
}
.empty-cart{
background: #202020;
padding: 10px;
color: #fff;
text-align: center;
position: relative;
}
【问题讨论】:
-
您是否需要隐藏/可见子菜单具有比顶部菜单更大的特定设置宽度?
-
是的,因为当您将产品添加到购物车时,购物车的宽度不会与顶部菜单相同,因此我希望它的宽度大于顶部菜单。子菜单可以与右侧的按钮对齐,但在左侧我希望它更大。
-
好的,那我的回答会解决的。
标签: html css button drop-down-menu hover