日期:2014-05-16  浏览次数:20684 次

div设置宽度无效
css文件

body{
margin:0;
padding:0;
font-size:16px;
background-image:url(/CMS/view/image/background.jpg);
z-index:0;
}
#body{
margin:auto;
width:100%;
height:auto;
}
.nav{
width:100%;
height:30px;
background-color:DAECFE;
position:fixed;
top:0;
z-index:100;
}

#centent{
margin-top:34px;
margin-left:auto;
margin-right:auto;
width:1024px;

border:solid #C9C9C9;
height:600px;
}
#footer{
margin-top:5px;
margin-left:auto;
margin-right:auto;
width:1024px;
height:60px;
border:solid #C9C9C9;
}

html文件

<html>

<head>
<meta charset="utf-8">
<title> cms管理系统</title>
    <link href="/CMS/view/css/index.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div class="nav">导航栏</div>
   
    <div id="centent">类容</div>
    <dib id="footer">footer</div>
</body>
</html>

显示如下:
,宽度无效,也没剧中显示。
把footer加入浮动float:left属性后宽度有效。如图

求大神解答。
css html

------解决方案--------------------
引用:
Quote: 引用:

/CMS/view/css/index.css

这个 标签先删除

或者 你看浏览器 元素调试
看那些样式被影响了
谢谢了,解决了。在footer中加入display:block;属性就可以正常显示了。但我不晓得原因。

所以说 你被其他地方的样式 影响了
------解决方案--------------------

引用:
Quote: 引用:

/CMS/view/css/index.css

这个 标签先删除

或者 你看浏览器 元素调试
看那些样式被影响了
谢谢了,解决了。在footer中加入display:block;属性就可以正常显示了。但我不晓得原因。

好多浏览器对div的宽度,要指定百分比的形式,必须写display:block