网页中img标签图片排版在工作中经常会遇到,如果图片大小比例不一样,想整齐对应排列会让图片变形,本文介绍CSS如何实现图片等比例缩放不变形。

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>等比例不变形</title>
<style type="text/css">
	.pic li{width: 150px; height: 80px; float: left; list-style: none; margin: 10px; border: 1px solid #d8d8d8; padding: 5px; text-align: center;}
	.pic img{width: auto; height: auto; max-width: 100%; max-height: 100%;
	}  
</style>
</head>
<body>
	<div class="pic">
		<li><img src="https://www.baidu.com/img/flexible/logo/pc/result.png" alt=""></li>
		<li><img src="https://www.jb51.net/images/logo.gif" alt=""></li>
		<li><img src="//img.jbzj.com/image/sjb51-296-183.gif" alt=""></li>
	</div>
</body>
</html>