我对CSS非常陌生 - 我说的是我昨天开始学习它。无论如何,我有一个100%宽度的下拉菜单栏,我想让菜单中的内容(链接)居中。我整天都用Google搜索并尝试了很多不同的东西,但似乎无法弄明白。这是我的CSS:
.menu{
border:none;
text-align:center;
border:0px;
margin:0px;
width:100%;
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:#333333;
height:35px;
list-style:none;
margin:0;
padding:0;
}
.menu li{
float:left;
padding:0px;
}
.menu li a{
background:#333333 url(seperatornew.gif") bottom right no-repeat;
color:#cccccc;
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: #c20000 url("hovernew.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('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:#c20000 url('hover_subnew.gif') center left no-repeat;
border:0px;
color:#ffffff;
text-decoration:none;
}
.menu p{
clear:left;
}
我的HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/htm/strict.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type">
<link rel="stylesheet" type="text/css" href="test.css">
<style>
body {margin:0}
}</style>
</head>
<body marginwidth="0" marginheight="0">
<center><img alt="" src="Banner2011New.gif"></center>
<link rel="stylesheet" type="text/css" href="menu_style2.css">
<div class="menu">
<style type="text/css">
a:link {
COLOR: #ffffff;
}
a:visited {
COLOR: #ffffff;
}</style>
<ul>
<li><a target="_self" href="home2.htm">Home</a></li>
<li><a target="_self" href="viewlistings.htm">View Listings</a></li>
<li><a target="_self" href="aboutus2.htm">About Us</a>
<ul>
<li><a target="_self" href="judybio2.htm">Judy's Bio</a></li>
<li><a target="_self" href="stevebio2.htm">Steve's Bio</a></li>
<li><a target="_self" href="blakebio2.htm">Blake's Bio</a></li>
<li><a target="_self" href="mavbio2.htm">Maverick's Bio</a></li></ul></li>
<li><a target="_self" href="contact2.htm">Contact Info</a></li>
<li><a target="_self" href="emailus2.htm">E-Mail Us</a>
<ul>
<li><a target="_self" href="emailjudy.htm">E-Mail Judy</a></li>
<li><a target="_self" href="emailsteve.htm">E-Mail Steve</a></li>
<li><a target="_self" href="emailblake.htm">E-Mail Blake</a></li></ul></li></ul></div>
<p> </p>
<p> </p>
<center> </center>
</body>
</html>
我正在使用的菜单的实例如下:www.judyandsteve.com/test.htm
谢谢!
答案 0 :(得分:3)
.menu ul {
text-align: center;
}
.menu ul li {
display: inline-block;
#display: inline;
zoom: 1;
text-align: left;
}