gpt4 book ai didi

jquery - 水平居中对齐嵌套 ul li

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

好吧,我只是想设计一个导航菜单,这样当我将鼠标悬停在菜单项上时,它会 fork 出一个带有子菜单的水平子列表,直到一切正常。但现在我希望子列表应该相对于其父列表居中对齐。这看起来像这样用等号(=)绘制,请帮助。

  =        =      =
= = = = = = = =

这是 HTML 结构:

 <ul>  
<li><a href="jjbrides.php" rel="pageUrl">collection</a>
<ul>
<li><a href="jjbrides.php" rel="pageUrl">JJ brides</a></li>
<li><a href="maketime-stop.php" rel="pageUrl" class="subnav">make time stop</a></li>
<li><a href="jjbrides.php" rel="pageUrl">JJ brides</a></li>
<li><a href="maketime-stop.php" rel="pageUrl" class="subnav">make time stop</a></li>
</ul>
</li>
<li><a href="upcoming-event.php" rel="pageUrl">events</a>
<ul>
<li><a href="upcoming-event.php" rel="pageUrl">upcoming</a></li>
</ul>
</li>
</ul>

/* CSS样式*/

.nav > li {
line-height: 20px;
text-align: center;
float: left;
list-style: none;
}
.nav li a {
color: #737663;
display: block;
text-decoration: none;
text-align: center;
opacity: 1;
padding: 10px 42px;
font-family:'sangbleu_bp_sanslight';
text-transform:lowercase
}
.nav > li > a {
text-transform: lowercase;
font-size:20px;
}
.nav li.navhover > a {
color: #737663!important;
text-decoration: none;
opacity: 1;
}
.nav li a:active, .nav li a:focus {
text-decoration: none;
}
/*.nav li > ul{margin-left: 20px;}*/
.nav li> ul li a {
text-transform: lowercase;
font-family:'FarnhamDisplay-LightItal'!important;
font-size:18px;
}
.nav li ul li a {
text-transform: lowercase;
color:#737663;
padding:10px 20px!important;
}
.nav li.navhover ul li:hover a {
color: #737663;
opacity: 1;
}
.nav li > ul {
display: none;
margin: 0 0 0 20px;
padding:0;
list-style:none;
float: left;
position: absolute;
width: 500px;
z-index: 10;
}
.nav li.navhover > ul {
display: block;
}
.nav li ul li {
padding:0;
margin-top:3px;
float: left;
display: inline-block;
}
.nav li ul li:hover a, .inviewlink {
border-bottom:3px solid #737663;
}
.inviewlink:hover {
margin-bottom:-3px
}
.nav > li.active, .nav > li.active:hover {
/*background-color: #eee;*/
}
.nav > li.active a {
color:#737663
}
.nav > li.active:before {
width:100%;
height:100%;
content:' ';
visibility:visible;
top:0;
left:0;
z-index:10;
}
.nav > li.active > ul {
display:block;
}
.nav > li:first-child + li {
margin-right: 365px;
}
.nav > .sidebar-brand {
height: 55px;
line-height: 55px;
font-size: 18px;
}
.nav>li {
z-index:1
}
.nav li.navhover {
z-index:3
}
.nav li.navhover:after {
content:' ';
display:block;
width: 3000px;
background:#fff;
position:absolute;
z-index: 1;
/* top:0; */
height: 45px;
left: -1000px;
}

最佳答案

您好,您应该检查此示例子菜单中的此链接位于中心位置,希望对您有所帮助。

* { margin:0; padding:0; }
.nav{
display:block;
list-style:none;
text-align: left;
position: relative;
height: 30px;
}
.nav li {
display: block;
position: relative;
float: left;
border: 1.5px solid #FFF;
}
.nav li a {
width: 125px;
height: 30px;
display: table-cell;
vertical-align: middle;
text-decoration: none;
font-size: 12px;
font-family: Arial, Verdana, Helvetica, sans-serif;
text-align: center;
color: #000;
z-index: 2000;
background-color: #999;
}
li.active {
background-color: #999 ;
color: #000;
}
.nav li a:hover {
top: 30px;
}

.nav li:hover > a {
color:#fff;
background-color:#333;
}

.nav li ul {
width: 125px;
height: 25px;
position: absolute;
left: -9999px;
border: 1.5px solid #FFF;
}
.nav li:hover ul {
left: -2px;
}

.nav li li:hover > a {
color:#000;
background-color:#999;
}

.nav li li{
position: relative;
border: 1.5px solid #FFF;
height: 25px;

}
.nav li li a {
height: 25px;
top: 25px;
text-decoration: none;
font-size: 9px;
font-family: Arial, Verdana, Helvetica, sans-serif;
text-align: center;
display: table-cell;
vertical-align: middle;
color: #000;
z-index: 2000;
background-color: #999;
}
li li.active {
background-color: #a9d9d9 ;
color: #007f7b;
}

.nav li li:hover ul {
left: -2px;
top: 25px;
}

ul.nav li > ul {
width: 700px;
height: 25px;
background-color:red;
}

ul.nav li > ul > li > ul {
background-color:green;
height: 25px;
}

ul.nav li > ul > li { display: none; }
ul.nav li:hover li { display: block; }

DEMO

关于jquery - 水平居中对齐嵌套 ul li,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25362069/

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