中心导航按钮
我想将导航栏按钮居中,但由于某种原因,它们距离右侧太远。这是为什么??
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link href="css/mainStyle.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="js/jquery.js"></script>
<script language="javascript">
function start() {
hideAll();
$('#about').show();
}
function hideAll() {
$('#home').hide();
$('#contact').hide();
}
function slideAll() {
$('#home').slideUp();
$('#contact').slideUp();
}
$(document).ready(function() {
start();
});
</script>
</head>
<body>
<style type="text/css">
body {
background-color: #f3f3f3;
}
div.banner {
width: 800px;
height: 200px;
margin-left: auto;
margin-right: auto;
border: 1px solid black;
text-align: center;
background: white;
}
div.main {
width: 800px;
height: auto;
margin: 40px auto 50px auto;
background-color: white;
padding: 20px;
}
p {
font-family: Helvetica;
font-weight: 100;
text-indent: 0px;
margin-bottom: 40px;
}
div.heading {
font-size: large;
text-transform: uppercase;
font-family: Helvetica;
font-weight: bolder;
margin-bottom: 20px;
}
.answer {
font-family: Helvetica;
font-weight: 100;
margin-left: 60px;
}
p.question {
font-family: Helvetica;
margin: 0px 0px 0px 0px;
text-indent: -13px;
padding-left: 13px
}
#shadow {
-webkit-box-shadow: 0px 0px 4px #000000;
-moz-box-shadow: 0px 0px 4px #000000;
box-shadow: 0px 0px 4px #000000;
}
</style>
<div class="banner">
BANNER
</div>
<nav id="navcontainer">
<ul id="navlist">
<li id="button"><a onclick="hideAll(); $('#home').slideDown();" id="current">Home</a></li>
<li id="button"><a href="#">Past Summer Camps</a></li>
<li id="button"><a onclick="hideAll(); $('#contact').slideDown();">About Summer Camps</a></li>
<li id="button"><a href="#">Apply</a></li>
<li id="button"><a onclick="hideAll(); $('#contact').slideDown();">Contact</a></li>
<li id="button"><a href="#">Photo Gallery</a></li>
</ul>
</nav>
<div class="main" id="shadow">
</div>
<div id="about">
</div>
<div id="contact">
CONTACT
</div>
</div>
</body>
</html>
和 CSS:
#navcontainer ul
{
list-style-type: none;
width: 100%;
margin-left: auto;
margin-right: auto;
text-align: center;
margin-top: 40px;
}
#button { display: inline; }
li a
{
text-decoration: none;
color: black;
padding: 8px;
margin-right: 30px;
-moz-border-radius: 6px;
-webkit-border-radius: 6px;
border-radius: 6px;
background: #eeeeee; /* old browsers */
background: #eeeeee; /* old browsers */
background: -moz-linear-gradient(top, #eeeeee 0%, #A0A0A0 100%); /* firefox */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#eeeeee), color-stop(100%,#A0A0A0)); /* webkit */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#eeeeee', endColorstr='#A0A0A0',GradientType=0 ); /* ie */
-webkit-box-shadow: 0px 0px 3px #000000;
-moz-box-shadow: 0px 0px 3px #000000;
box-shadow: 0px 0px 3px #000000;
text-transform: uppercase;
font: 22px 'HomeRemedy', Arial, sans-serif;
font-size: 12px;
font-weight: bold;
}
li a:hover
{
background: #353535;
color: #fff;
}
I want to center my nav bar buttons, but for some reason, they're too far to the right. Why is this??
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link href="css/mainStyle.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="js/jquery.js"></script>
<script language="javascript">
function start() {
hideAll();
$('#about').show();
}
function hideAll() {
$('#home').hide();
$('#contact').hide();
}
function slideAll() {
$('#home').slideUp();
$('#contact').slideUp();
}
$(document).ready(function() {
start();
});
</script>
</head>
<body>
<style type="text/css">
body {
background-color: #f3f3f3;
}
div.banner {
width: 800px;
height: 200px;
margin-left: auto;
margin-right: auto;
border: 1px solid black;
text-align: center;
background: white;
}
div.main {
width: 800px;
height: auto;
margin: 40px auto 50px auto;
background-color: white;
padding: 20px;
}
p {
font-family: Helvetica;
font-weight: 100;
text-indent: 0px;
margin-bottom: 40px;
}
div.heading {
font-size: large;
text-transform: uppercase;
font-family: Helvetica;
font-weight: bolder;
margin-bottom: 20px;
}
.answer {
font-family: Helvetica;
font-weight: 100;
margin-left: 60px;
}
p.question {
font-family: Helvetica;
margin: 0px 0px 0px 0px;
text-indent: -13px;
padding-left: 13px
}
#shadow {
-webkit-box-shadow: 0px 0px 4px #000000;
-moz-box-shadow: 0px 0px 4px #000000;
box-shadow: 0px 0px 4px #000000;
}
</style>
<div class="banner">
BANNER
</div>
<nav id="navcontainer">
<ul id="navlist">
<li id="button"><a onclick="hideAll(); $('#home').slideDown();" id="current">Home</a></li>
<li id="button"><a href="#">Past Summer Camps</a></li>
<li id="button"><a onclick="hideAll(); $('#contact').slideDown();">About Summer Camps</a></li>
<li id="button"><a href="#">Apply</a></li>
<li id="button"><a onclick="hideAll(); $('#contact').slideDown();">Contact</a></li>
<li id="button"><a href="#">Photo Gallery</a></li>
</ul>
</nav>
<div class="main" id="shadow">
</div>
<div id="about">
</div>
<div id="contact">
CONTACT
</div>
</div>
</body>
</html>
and the CSS:
#navcontainer ul
{
list-style-type: none;
width: 100%;
margin-left: auto;
margin-right: auto;
text-align: center;
margin-top: 40px;
}
#button { display: inline; }
li a
{
text-decoration: none;
color: black;
padding: 8px;
margin-right: 30px;
-moz-border-radius: 6px;
-webkit-border-radius: 6px;
border-radius: 6px;
background: #eeeeee; /* old browsers */
background: #eeeeee; /* old browsers */
background: -moz-linear-gradient(top, #eeeeee 0%, #A0A0A0 100%); /* firefox */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#eeeeee), color-stop(100%,#A0A0A0)); /* webkit */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#eeeeee', endColorstr='#A0A0A0',GradientType=0 ); /* ie */
-webkit-box-shadow: 0px 0px 3px #000000;
-moz-box-shadow: 0px 0px 3px #000000;
box-shadow: 0px 0px 3px #000000;
text-transform: uppercase;
font: 22px 'HomeRemedy', Arial, sans-serif;
font-size: 12px;
font-weight: bold;
}
li a:hover
{
background: #353535;
color: #fff;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的链接有右边距。将其减少一半并添加左边距:
http://jsfiddle.net/CsJ8J/
You have a right margin on your links. Reduce it by half and add a left margin:
http://jsfiddle.net/CsJ8J/
我不得不提的是,拥有多个同名 id 是无效的。您应该删除 id="button" 引用。
最后,这可能对您有用:
http://jsfiddle.net/CsJ8J/1/
I have to mention that having multiple ids with the same name does not validate. You should remove the id="button" reference.
Last, this might work for you:
http://jsfiddle.net/CsJ8J/1/
只需在上面添加这个,它就会将它们居中
just add this above and it will center them