怎么让div居中?是整个div居中,不是div中的内容居中。

fihuang 2009-10-31 11:15:08
怎么让div居中?是整个div居中,不是div中的内容居中。
在页面上最外层有一个div,然后页面上显示的所有的内容都放在这个div中,请问如何让最外层的这个div居中?

<html>
<body>
<div>
</div>
</body>
</html>
...全文
403655 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
liangjiesheng 2011-11-05
  • 打赏
  • 举报
回复
14楼OK
emofeng1216 2011-09-19
  • 打赏
  • 举报
回复
margin:0px auto;
text-align:center;

“text-align:center; ”这句必须有
刘畅8877 2011-08-31
  • 打赏
  • 举报
回复
margin:0px auto 这个不太好吧,IE 6 对这个属性不兼容。。。很郁闷。。
fihuang 2010-10-22
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 ni45ok 的回复:]

不好用,根本不行啊margin:0 auto;它默认不就是这个啊?那不等于没写
[/Quote]你要给div设置一个宽度的
future@2020 2010-10-15
  • 打赏
  • 举报
回复
不好用,根本不行啊margin:0 auto;它默认不就是这个啊?那不等于没写
f452108618 2010-09-18
  • 打赏
  • 举报
回复
这么0px后还跟了个auto
f452108618 2010-09-18
  • 打赏
  • 举报
回复
margin:0px auto这句是什么意思啊
fihuang 2009-10-31
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 kendyjack 的回复:]
引用 4 楼 fihuang 的回复:
引用 3 楼 works07 的回复:
.wrap{margin:0 auto}
这个wrap是什么意思?html代码中要写什么东西才能用到wrap。

晕,他写的是个class
不过记得要设个width
不然不会居中的
[/Quote]原来这样,谢了。
另外,一定要写width啊!我的原意是这个div只是居中,是个空壳子,里面的内容能撑多宽就撑多宽。这下好了,要重新设计了。
jenny0810 2009-10-31
  • 打赏
  • 举报
回复
.wrap{margin:0 auto;width:960px;}
<html>
<body>
<div class="wrap">
</div>
</body>
</html>
夜雨_Jason 2009-10-31
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 fihuang 的回复:]
引用 3 楼 works07 的回复:
.wrap{margin:0 auto}
这个wrap是什么意思?html代码中要写什么东西才能用到wrap。
[/Quote]
晕,他写的是个class
不过记得要设个width
不然不会居中的
fihuang 2009-10-31
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 works07 的回复:]
.wrap{margin:0 auto}
[/Quote]这个wrap是什么意思?html代码中要写什么东西才能用到wrap。
works07 2009-10-31
  • 打赏
  • 举报
回复
.wrap{margin:0 auto}
zhong0711101 2009-10-31
  • 打赏
  • 举报
回复
margin: 0 auto;
Helen_Chai 2009-10-31
  • 打赏
  • 举报
回复
div居中:
margin: 0 auto;

text居中:
text-align:center;

try it!
kkshiba 2009-10-31
  • 打赏
  • 举报
回复
<!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=utf-8" />
<title>层居中的问题</title>
<style type="text/css">
<!--
body{width:720px;margin:0px auto}
#box{
border:1px solid;
width:720px;
}
#left{
width:150px;
height:150px;
background-color:blue;
border:1px dotted;
float:left;
}
#main{
width:150px;
height:152px;
background-color:red;
border:1px dotted;
float:left

}
#right{
width:150px;
height:150px;

border:1px dotted;
float:left

}
-->
</style>
</head>

<body>
<div id="box">
<div id="left">left</div>
<div id="main">main</div>
<div id="right"><img src="http://www.dttit.com/img/talk.gif" width="149" height="150"></div>
</div>
</body>
</html>

这样就可以让层居中 了

61,112

社区成员

发帖
与我相关
我的任务
社区描述
层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。
社区管理员
  • HTML(CSS)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧