gpt4 book ai didi

css - 有菜单按钮居中的CSS下拉菜单

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

我正在使用此 CSS 来设计我的菜单样式。菜单 li 当前设置为 float: left,这显然将它们定位在左侧,但我真的希望它们居中。

谁能帮我修改一下?

.menu{

border:none;
border:0px;
margin:0px;
padding:0px;
font: 67.5% "Lucida Sans Unicode", "Bitstream Vera Sans", "Trebuchet Unicode MS", "Lucida Grande", Verdana, Helvetica, sans-serif;
font-size:14px;
font-weight:bold;
}
.menu ul{

background:#6991B7;
height:35px;
list-style:none;
margin:0;
padding:0;

}
.menu li{

float:left;
padding:0px;

}
.menu li a{
background:#6991B7 url("images/seperator.gif") bottom right no-repeat;
color:#FFF;
display:block;
font-weight:normal;
line-height:35px;
margin:0px;
padding:0px 25px;
text-align:center;
text-decoration:none;
}
.menu li a:hover, .menu ul li:hover a{
background: #2580a2 url("images/hover.gif") bottom center no-repeat;
color:#FFFFFF;
text-decoration:none;
}
.menu li ul{
background:#333333;
display:none;
height:auto;
padding:0px;
margin:0px;
border:0px;
position:absolute;
width:225px;
z-index:200;
/*top:1em;
/*left:0;*/
}
.menu li:hover ul{
display:block;

}
.menu li li {
background:url('images/sub_sep.gif') bottom left no-repeat;
display:block;
float:none;
margin:0px;
padding:0px;
width:225px;
}
.menu li:hover li a{
background:none;

}
.menu li ul a{
display:block;
height:35px;
font-size:12px;
font-style:normal;
margin:0px;
padding:0px 10px 0px 15px;
text-align:left;
}
.menu li ul a:hover, .menu li ul li:hover a{
background:#2580a2 url('images/hover_sub.gif') center left no-repeat;
border:0px;
color:#ffffff;
text-decoration:none;
}
.menu p{
clear:left;
}

最佳答案

嘿,我想你想要你的 navi 显示中心检查这段代码,我在你的 css 代码中做了一些修改

1. text-align:center put to .menu css
2. .menu li, .menu li a define to display:inline-block;
3. .menu ul define margin: 0 auto; and overflow:hidden;

CSS

    .menu{

border:none;
border:0px;
margin:0px auto;
padding:0px;
font: 67.5% "Lucida Sans Unicode", "Bitstream Vera Sans", "Trebuchet Unicode MS", "Lucida Grande", Verdana, Helvetica, sans-serif;
font-size:14px;
font-weight:bold;
text-align:center;
}
.menu ul{

background:#6991B7;
height:35px;
list-style:none;
margin:0 auto;
padding:0;
overflow:hidden;

}
.menu li{

display:inline-block;
padding:0px;

}
.menu li a{
background:#6991B7 url("images/seperator.gif") bottom right no-repeat;
color:#FFF;
display:inline-block;
font-weight:normal;
line-height:35px;
margin:0px;
padding:0px 25px;
text-decoration:none;
}
.menu li a:hover, .menu ul li:hover a{
background: #2580a2 url("images/hover.gif") bottom center no-repeat;
color:#FFFFFF;
text-decoration:none;
}
.menu li ul{
background:#333333;
display:none;
height:auto;
padding:0px;
margin:0px;
border:0px;
position:absolute;
width:225px;
z-index:200;
/*top:1em;
/*left:0;*/
}
.menu li:hover ul{
display:block;

}
.menu li li {
background:url('images/sub_sep.gif') bottom left no-repeat;
display:block;
float:none;
margin:0px;
padding:0px;
width:225px;
}
.menu li:hover li a{
background:none;

}
.menu li ul a{
display:block;
height:35px;
font-size:12px;
font-style:normal;
margin:0px;
padding:0px 10px 0px 15px;
text-align:left;
}
.menu li ul a:hover, .menu li ul li:hover a{
background:#2580a2 url('images/hover_sub.gif') center left no-repeat;
border:0px;
color:#ffffff;
text-decoration:none;
}
.menu p{
clear:left;
}

HTML

<div class="menu">
<ul>
<li><a href="#">Demo link</a></li>
<li><a href="#">Demo link</a></li>
<li><a href="#">Demo link</a></li>
<li><a href="#">Demo link</a></li>
<li><a href="#">Demo link</a></li>
<li><a href="#">Demo link</a></li>
</ul>
</div>

现场演示 http://jsfiddle.net/rohitazad/g3hLK/1/

关于css - 有菜单按钮居中的CSS下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10290145/

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