求高手解答DIV导航部分居中问题

来源:百度知道 编辑:UC知道 时间:2024/06/23 15:57:08
代码如下,如何设置#menu让导航在网页里居中呢?(已经试过BODY和#menu中单加入margin:0 auto;无效)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>111</title>
<link rel="stylesheet" href="css.css" type="text/css" media="screen" />
</head>
<body>
<div id="head">
</div>
<div id="line1">
</div>
<div id="menu" style="margin:0 auto">
<ul id="menu

主要就是你很多东西没给width这个属性,他不知道多宽怎么给你居中,默认的是填满全屏的。还有就是ID值不可以一样,否者到JAVASCRIPT会出错的。我给你改了下源代码,你看看。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>111</title>
<link rel="stylesheet" href="css.css" type="text/css" media="screen" />
<style>
<!--
#menu{height:30px}
#menuul{ margin:0 auto; height:15px;width:400px; text-align:center;}
#menu li{ float:left; margin-left:10px; background:#CF3;}
a{ text-decor