导航
  • 全部
...

如何让DIV垂直居中

letian003 2008-04-25 09:16:07
在一个页面中,只有一个DIV,请问如何使这个DIV垂直居中呢,
...全文
给本帖投票
3413 13 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
GossZhang 2011-03-13
  • 打赏
  • 举报
回复
只求一看,
knowledge_Is_Life 2008-05-01
  • 打赏
  • 举报
回复
没遇到过这种情况.
wuzhongbo 2008-04-26
  • 打赏
  • 举报
回复
<style>
#div1 {
position: absolute;
width:100px;
height:50px;
left:50%;
top:50%;
margin-left:-50px;
margin-top:-25px;
border:1px solid #000
}
</style>
<body>
<div id="div1"></div>
</body>
ten789 2008-04-26
  • 打赏
  • 举报
回复
body 设置高度 相对 绝对都可以

然后各区块就可以设定高度了
yagas 2008-04-26
  • 打赏
  • 举报
回复
<!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>
.dd { width:300px; height:30px; margin:0px auto; border:1px solid #000000 }
</style>
</head>

<body>
<div class="dd"></div>
</body>
</html>
letian003 2008-04-25
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 sunfan1010 的回复:]
<html>
<style>
#center {
background: #090;
width: 100px;
height: 96px;
position: relative;
left: 50%;
margin-left: expression(-(this.offsetWidth/2)+"px");
margin-top:20%;

}
</style>
<div id='center'>
</div>
[/Quote]


这个这样子写可能更好一点。
<style>
#center {
background: #090;
width: 100px;
height: 96px;
position: relative;
margin:20% auto auto;
}
</style>
</head>

<body>
<html>

<div id='center'>
fffffff
</div>
</body>
</html>
beeqee 2008-04-25
  • 打赏
  • 举报
回复
http://www.blueidea.com/tech/web/2006/3231.asp
CSS实现完美垂直居中
striker_un 2008-04-25
  • 打赏
  • 举报
回复
通常在ie和ff下是两种方式。


<style>
/**我是考虑到层的高度,设为百分之43*/
.myDiv{

position: fixed;
top: 43%;
left: 50%;
margin-left: -300px;
width:500px;
border: 1px solid #93a6aa;
background-color:#dfe6ed;
padding: 10px;
}


* html .myDiv{
position: absolute;
width:600px;
top: expression((document.documentElement.scrollTop || document.body.scrollTop) + Math.round(43 * (document.documentElement.offsetHeight || document.body.clientHeight) / 100) + 'px');
}
</style>


<div class="myDiv"> 这个居中了没有?</div>
jy_1201 2008-04-25
  • 打赏
  • 举报
回复
DIV+TABLE不好吧,还是直接用CSS实现吧。

------------------------------------------
酷得组件仓库 - 第三方软件开发组件下载\试用
www.cookcode.net
daxian22 2008-04-25
  • 打赏
  • 举报
回复
<div><table width=100% height=100%><tr><td></td></tr></table></div>
sunfan1010 2008-04-25
  • 打赏
  • 举报
回复
<html>
<style>
#center {
background: #090;
width: 100px;
height: 96px;
position: relative;
left: 50%;
margin-left: expression(-(this.offsetWidth/2)+"px");
margin-top:20%;

}
</style>
<div id='center'>
</div>
jayflee 2008-04-25
  • 打赏
  • 举报
回复

<BODY>

<TABLE height="100%">
<TR>
<TD>
<div>
aaaaaaaaaaaa
</div>
</TD>
</TR>
</TABLE>
</BODY>
letian003 2008-04-25
  • 打赏
  • 举报
回复
都不是太满意呀,有没有更好一点的方法呀。

21,894

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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

手机看
关注公众号

关注公众号

客服 返回
顶部