这是我的 HTML 布局:
<ul class="main-menu">
<li class="sub">
Sections
<ul>
<li>Add Section</li>
<li>Edit Sections</li>
</ul>
</li>
<li></li>
<li></li>
<li></li>
<li></li>
和 CSS
* {
margin: 0px;
padding: 0px;
border-top-style: none;
border-right-style: none;
border-bottom-style: none;
border-left-style: none;
list-style-type: none;
}
.main-menu {
font-family: Tahoma, Geneva, sans-serif;
font-size: 13px;
color: #000;
display: inline-block;
margin-top: 15px;
margin-bottom: 15px;
margin-left: 15px;
}
.main-menu > li {
height: 22px;
width: 170px;
background: rgb(178,225,255); /* Old browsers */
background: -moz-linear-gradient(top, rgba(178,225,255,1) 0%, rgba(102,182,252,1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(178,225,255,1)), color-stop(100%,rgba(102,182,252,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(178,225,255,1) 0%,rgba(102,182,252,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(178,225,255,1) 0%,rgba(102,182,252,1) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(178,225,255,1) 0%,rgba(102,182,252,1) 100%); /* IE10+ */
background: linear-gradient(to bottom, rgba(178,225,255,1) 0%,rgba(102,182,252,1) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#b2e1ff', endColorstr='#66b6fc',GradientType=0 ); /* IE6-9 */
margin-bottom: 7px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
-webkit-box-shadow: 0px 3px 5px rgba(70, 58, 70, 0.70);
-moz-box-shadow: 0px 3px 5px rgba(70, 58, 70, 0.70);
box-shadow: 0px 3px 5px rgba(70, 58, 70, 0.70);
cursor: pointer;
text-align: right;
padding-top: 5px;
padding-right: 10px;
font-family: Tahoma, Geneva, sans-serif;
font-size: 13px;
}
.main-menu li:hover {
-webkit-box-shadow: 0px 3px 5px rgba(70, 58, 70, 0.30);
-moz-box-shadow: 0px 3px 5px rgba(70, 58, 70, 0.30);
box-shadow: 0px 3px 5px rgba(70, 58, 70, 0.30);
color: #CC0000;
}
.main-menu li ul {
display: none;
}
.main-menu > li.sub:hover ul {
display: block;
}
我正在使用css-gradient
forli
元素,因此它会固定width
,并且height
当我将鼠标悬停在li
显示子菜单上时,它会起作用,但li
由于已固定,它在 main 下没有适合的位置width
。
我想要一个解决方案,以便我可以使用gradient
和显示子菜单