<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
img {
width: 100%;
height: auto !important;
}
</style>
</head>
<body>
<img src="images/common/1/1.jpg" style="">
<!--这里的img标签 width:100%;height: auto;图片会自动展开铺满屏幕-->
</body>
<script type="text/javascript">
</script>
</html>
这里的img标签 width:100%;height: auto;图片会自动展开铺满屏幕,为什么?
img
的父级是body,body
默认是100%,当img
宽度为100%,也就是body大小宽,高为auto
,则图片随着宽自适应。