div代码居中 上下居中 左右居中
来源:互联网 发布:windows 能用final cut 编辑:程序博客网 时间:2024/04/30 22:07
<!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>Universal vertical center with css</title>
<style>
#outer {
height:300px;
width:300px;
overflow:hidden;
position:relative;
text-align:center;
}
#outer[id]{
display:table;
position:static;
}
#middle{
position:absolute;
top:50%;
}
/* for explorer only*/
#middle[id]{
display:table-cell;
vertical-align:middle;
position:static;
}
#inner{
position:relative;
top:50%;
}
/* for explorer only*/
/* optional : #inner[id] {position:static}*/
.withBorder{
border:1px green solid;
}
</style>
</head>
<body>
<div id="outer" class="withBorder">
<div id="middle">
<div id="inner">
<img src="http://blog.163.com/lixiaofengfly@126/blog/image/guest_test_icon2.jpg"/>
<!-- any text any height any content,
everthing is vertically centered.
或者文字也可以
只需要设置 outer 的 高度 宽度 就可以得到想要的效果了
其他... 复制!
-->
</div>
</div>
</div>
</body>
</html>
精简后的代码
<!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>Universal vertical center with css</title>
<style>
#outer {
height:300px;
width:300px;
display:table-cell;
vertical-align:middle;/*火狐,chrom垂直居中*/
line-height:300px; /*IE7垂直居中*/
text-align:center; /*水平居中*/
}
.withBorder{
border:1px green solid;
}
</style>
</head>
<body>
<div id="outer" class="withBorder">
<img src="http://blog.163.com/lixiaofengfly@126/blog/image/guest_test_icon2.jpg"/>
</div>
</body>
</html>
- div代码居中 上下居中 左右居中
- div左右上下居中
- div的上下居中,左右居中,左右上下都居中
- div+css:页面整体布局居中显示:上下居中||垂直居中,左右居中||水平居中
- 如何让图片在div里左右居中,上下居中
- Div 与 CSS 如何实现上下居中 左右居中
- Div上下居中
- Div上下居中 (html)
- css图片左右上下居中
- HTML:div内容上下居中
- div中文字上下居中
- html div左右/垂直居中
- Word表格如何设置上下居中对齐、左右居中对齐
- div+css居中代码
- div居中代码
- div居中代码
- div垂直居中 css div盒子上下垂直居中
- CSS实现div垂直居中 div上下居中显示
- OpenCV Learning: 视频播放控制,滚动条可控
- iPhone/iPad全屏截图与区域截图
- 链接到最近访问的单元格
- PHP如何解决网站大流量与高并发的问题
- STM32 USB转串口CDC官方示例程序修正
- div代码居中 上下居中 左右居中
- va_list用法
- 一致性hash算法 - consistent hashing
- 生成透明的图形
- 遍历系统的所有ObjectType和TypeIndex
- EDM电子邮件营销实施条件和邮件列表分析
- Ext.tip.ToolTip 提示
- JavaScript可否多线程? 深入理解JavaScript定时机制
- 学习笔记——函数插值