我有这个问题 我无法将这个简单的 CSS Horizontam 菜单居中 你能帮我怎么做吗? 所以这是我的 CSS 代码
<style>
{
float:left;
width:100%;
padding:0;
margin:0;
list-style-type:none;
}
a
{
float:left;
width:6em;
text-decoration:none;
color:white;
background-color:purple;
padding:0.2em 0.6em;
border-right:1px solid white;
border-left:1px solid white;
}
a:hover {background-color:#ff3300;}
li {display:inline;}
</style>
这是我的html
</head>
<body bgcolor="gray">
<font face="calibri">
<center><img style="float:center" src="header.jpg" alt="" ></center>
<center>
<ul>
<li><a href="#">HOME</a></li>
<li><a href="#">EVENTS</a></li>
<li><a href="#">VIDEOS</a></li>
<li><a href="#">CONTACT US</a></li>
</center>
</ul>
谢谢你帮助我 我只是这里的新成员。 请回复谢谢
最佳答案
使用 text-align: center
并删除 ul
和 a
标签上的所有 float: left
。
ul {
width:100%;
padding:0;
margin:0;
list-style-type:none;
text-align: center;
}
关于html - CSS如何使水平菜单居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21964188/