码迷,mamicode.com
首页 > 其他好文 > 详细

图片山下左右居中

时间:2016-10-08 14:01:15      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:

方法一:

<!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>phone center</title>
<style type="text/css">

.box{
width:100px;
height:100px;
border:1px solid #ccc;
text-align:center;
border:1px solid #ccc;
}
.box img{
vertical-align:middle;
max-width:100%;
}
.box span{
display:inline-block;
height:100%;
width:0px;
overflow:hidden;
vertical-align:middle;
background:red;
}
</style>
</head>

<body>
<div class="box">
<img src="ceshi/images/head-img.png" /><span></span>
</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=utf-8" />
<title>phone center</title>
<style type="text/css">
.box{
width:100px;
height:100px;
display:table-cell;
text-align:center;
vertical-align:middle;
border:1px solid #ccc;
}
</style>
</head>

 

<body>
<div class="box">
<img src="ceshi/images/head-img.png" />
</div>
</body>
</html>

 方法三:

<style>

#box{width:500px;height:500px;position:relative;}
#box img{width:100px;height:100px;position:absolute;top:50%;left:50%;margin-top:-50px;margin-left:-50px}
</style>
<div id="box">
<img src="xxx.jpg">
</div>

 

图片山下左右居中

标签:

原文地址:http://www.cnblogs.com/jinsuo/p/5937966.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!