gpt4 book ai didi

CSS嵌套菜单自动宽度不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 13:39:43 25 4
gpt4 key购买 nike

我有这个嵌套菜单,从第三层级开始一切正常。

我这里有代码和结果:http://jsfiddle.net/wvsL9/

如果您悬停菜单:“PRODUKTER”,然后是“PRIVAT”,您会发现宽度问题不是“自动”。我真的被困在这里,我尝试了很多变体。你能找出为什么它不能像我想要的那样工作吗?

提前致谢

#menu, #menu ul {
margin: 0;
padding: 0;
list-style: none;
font-size: 0.9em;
font-family:'Helvetica Neue For BBC W01 Bd';
}

#menu:before,
#menu:after {
content: "";
display: table;
}

#menu:after {
clear: both;
}

#menu {
zoom:1;
}

#menu li {
float: left;
display: inline-block;
position: relative;
}

#menu li:last-child {
border: 0;
-moz-box-shadow: none;
-webkit-box-shadow: none;
box-shadow: none;
}


#menu a {
display: inline-block;
padding: 50px 8px;
color: #000;
text-transform: uppercase;
text-decoration: none;
font-weight: bold;
}

#menu li:hover > a {
background: #000;
color: #fff;
}

#menu li.current-menu-item a{
background: #000;
color: #FFF;
}

*html #menu li a:hover { /* IE6 only */
color: #fafafa;
}

#menu ul {
margin: 20px 0 0 0;
_margin: 0; /*IE6 only*/
opacity: 0;
visibility: hidden;
position: absolute;
width: 100%;
top: 120px;
left: 0;
z-index: 1;
background: #000;
-webkit-transition: all .2s ease-in-out;
-moz-transition: all .2s ease-in-out;
-ms-transition: all .2s ease-in-out;
-o-transition: all .2s ease-in-out;
transition: all .2s ease-in-out;
}

#menu li:hover > ul {
opacity: 1;
visibility: visible;
margin: 0;
}

#menu ul li {
position: static;
float: none;
display: block;
border: 0;
_line-height: 0; /*IE6 only*/
}

#menu ul li:last-child {
-moz-box-shadow: none;
-webkit-box-shadow: none;
box-shadow: none;
}


#menu ul a {
padding-top: 10px;
padding-bottom: 10px;
_height: 10px; /*IE6 only*/
display: block;
white-space: nowrap;
float: none;
text-transform: none;
color: #fff;
}

#menu ul a:hover {
background-color: #f60c0c;
}

#menu ul li:first-child > a {
-moz-border-radius: 3px 3px 0 0;
-webkit-border-radius: 3px 3px 0 0;
border-radius: 3px 3px 0 0;
}

#menu ul li:first-child > a:after {
content: '';
position: absolute;
left: 40px;
top: -6px;
}

#menu ul ul {
top: 0;
left: 100%;
margin: 0 0 0 20px;
_margin: 0; /*IE6 only*/
}

#menu ul ul li{
display: block;
width: auto;
float: none;
}

#menu ul ul li a{
display: block;
padding: 10px 50px;
}

#menu ul ul li:first-child a:after {
left: -6px;
top: 50%;
margin-top: -6px;
border-left: 0;
}

#menu ul li:first-child a:hover:after {
border-bottom-color: #04acec;
}

#menu ul ul li:first-child a:hover:after {
border-right-color: #0299d3;
border-bottom-color: transparent;
}

#menu ul li:last-child > a {
-moz-border-radius: 0 0 3px 3px;
-webkit-border-radius: 0 0 3px 3px;
border-radius: 0 0 3px 3px;
}

最佳答案

您可以在正确的元素上使用 width: auto;。只需添加:

#menu ul ul {
width: auto;
}

JSFiddle example

关于CSS嵌套菜单自动宽度不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22784222/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com