Css 控制图片上下居中,超出部分隐藏

<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
img{
width: 100%;
display: block;
}
div{
width: 600px;
height: 600px;
border: 1px solid red;
text-align: center;
overflow: hidden;
position: relative;
}
img{
position: absolute;
width: 100%;
top: 0;
bottom: 0;
left: 0;
margin: auto;
}
</style>

</head>
<body>
<div><img src="img/a.jpg" /></div>
</body>
</html>

posted @ 2017-08-18 13:16  wǒの湁茡潞釦﹌  阅读(1432)  评论(0编辑  收藏  举报