居中方法
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
/*第一种居中办法*/
#box{ margin: 60px auto;
width: 600px;
height: 500px;
background: darkgray;
position: relative;
}
.box1{ width: 300px;
height: 300px;
background: yellow;
position: absolute;
left: 50%;
top: 50%;
margin-left: -150px;
margin-top: -150px;
}
/*第二种居中的办法*/
.tu{margin: 60px auto;
width: 600px;
height: 500px;
border: 1px solid darkgoldenrod;
position: relative;
}
.tu img{ display: block;
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
margin: auto;}
</style>
</head>
<body>
<!--
作者:1600834563@qq.com
时间:2019-05-08
描述:第一种居中办法
-->
<div id="box">
<div class="box1"></div>
</div>
<!--
作者:1600834563@qq.com
时间:2019-05-08
描述:第二居中办法
-->
<div class="tu">
<img src="img/s1508271f1.jpg"/>
</div>
</body>
</html>
效果图: