首页 > 代码库 > 图片山下左右居中
图片山下左右居中
方法一:
<!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="http://www.mamicode.com/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="http://www.mamicode.com/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
>
图片山下左右居中