<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<style type="text/css">
.wrap {
width:1024
}
.list li {
display: block
float: left
width: 33%
text-align: center
}
</style>
<body>
<div class="wrap">
<ul class="list">
<li>12345</li>
<li>123</li>
<li>1555</li>
<li>1555</li>
<li>2222</li>
<li>12345</li>
<li>123</li>
<li>1555</li>
<li>1555</li>
<li>2222</li>
</ul>
</div>
</body>
</html>
比如你定义一个导航容器#navbar设置这个容器的宽度(比如960px),里面放你的导航,就是那个ul li列表,设置ul的宽度,这个宽度比你的导航容器宽度小,比如800px,然后设置ul的margin上下为零,左右自动,这样ul列表就相对navbar这个父容器居中了。css中,容器相对容器的居中都采用margin左右自动即可,文本居中用text-align,不过浮动元素不受这个控制不用锚点也可以平滑滚动到页面的指定位置复制代码
代码如下:
<!DOCTYPE
html>
<html
>
<head>
<meta
content="text/html
charset=utf-8"
/>
<title>ScrollTo:平滑滚动到页面指定位置</title>
<link
rel="stylesheet"
type="text/css"
href="../css/main.css"
/>
<style
type="text/css">
.nav{width:500pxmargin:10px
auto}
.nav
li{float:left
width:100px
height:24px
line-height:24px}
.box{height:500px}
.box
h3{height:32px
line-height:32px
padding-left:20px
font-size:14px}
.clear{clear:both}
html,body,div,span,h1,h2,h3,h4,h5,h6,p,pre,a,code,em,img,small,strong,sub,sup,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label{margin:0padding:0border:0outline:0font-size:100%vertical-align:baselinebackground:transparent}
a{color:#007bc4/*#424242*/
text-decoration:none}
a:hover{text-decoration:underline}
ol,ul{list-style:none}
table{border-collapse:collapseborder-spacing:0}
body{height:100%
font:12px/18px
"Microsoft
Yahei",
Tahoma,
Helvetica,
Arial,
Verdana,
"\5b8b\4f53",
sans-serif
color:#51555C
background:#162934
url(../images/body_bg.gif)
repeat-x}
img{border:none}
#main{width:910px
min-height:600px
margin:30px
auto
0
auto
background:#fff
-moz-border-radius:12px-khtml-border-radius:
12px-webkit-border-radius:
12px
border-radius:12px}
h2.top_title{margin:4px
20px
padding-top:15px
padding-left:20px
padding-bottom:10px
border-bottom:1px
solid
#d3d3d3
font-size:18px
color:#a84c10}
</style>
<script
type="text/javascript"
src="http://jt.875.cn/js/jquery.js"></script>
<script
type="text/javascript"
src="http://jt.875.cn/js/scrollto.js"></script>
<script
type="text/javascript">
$(function(){
$(".nav_pro").click(function(){
$.scrollTo('#pro',500)
})
$(".nav_news").click(function(){
$.scrollTo('#news',800)
})
$(".nav_ser").click(function(){
$.scrollTo('#ser',1000)
})
$(".nav_con").click(function(){
$.scrollTo('#con',1200)
})
$(".nav_job").click(function(){
$.scrollTo('#job',1500)
})
})
</script>
</head>
<body>
<div
id="main">
<h2
class="top_title">ScrollTo:平滑滚动到页面指定位置</h2>
<ul
class="nav">
<li><a
href="#"
class="nav_pro">产品展示</a></li>
<li><a
href="#"
class="nav_news">新闻中心</a></li>
<li><a
href="#"
class="nav_ser">服务支持</a></li>
<li><a
href="#"
class="nav_con">联系我们</a></li>
<li><a
href="#"
class="nav_job">人才招聘</a></li>
</ul>
<div
class="clear"></div>
<div
id="pro"
class="box">
<h3>产品展示</h3>
</div>
<div
id="news"
class="box">
<h3>新闻中心</h3>
</div>
<div
id="ser"
class="box">
<h3>服务支持</h3>
</div>
<div
id="con"
class="box">
<h3>联系我们</h3>
</div>
<div
id="job"
class="box"
style="height:680px">
<h3>人才招聘</h3>
</div>
</div>
</body>
</html>
JS
插件:scroll
to