源于生活

标题: 用CSS使图片上下左右都绝对居中于DIV [打印本页]

作者: kevin-ying    时间: 2015-9-17 08:47
标题: 用CSS使图片上下左右都绝对居中于DIV
[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=utf-8" />
<title>无标题文档</title>
<style>
<!--
* {margin:10;padding:10}
div {
width:180px;
height:180px;
border:1px solid #000;
position:relative;
display:table-cell;
text-align:center;
vertical-align:middle
}
div p {
position:static;
+position:absolute;
top:50%
}
div img {
position:static;
+position:relative;
top:-50%;left:-50%;
}
-->
</style></style>
</head>
<body>
<div>
<p><img src="http://date.kevin-ying.com/bbs_up/album/201410/24/084229vnhhthhsemkhhf5e.jpg" width="120" height="120" /></p>
</div>
<div>
<p><img src="http://date.kevin-ying.com/bbs_up/album/201410/24/084229vnhhthhsemkhhf5e.jpg" width="160" height="160" /></p>
</div>
<div>
<p><img src="http://date.kevin-ying.com/bbs_up/album/201410/24/084229vnhhthhsemkhhf5e.jpg" width="130" height="160" /></p>
</div>
<div>
<p><img src="http://date.kevin-ying.com/bbs_up/album/201410/24/084229vnhhthhsemkhhf5e.jpg" width="170" height="110" /></p>
</div>
</body>
</html>






欢迎光临 源于生活 (http://bbs.vingoo.info/) Powered by Discuz! X3.1