css - 如何设置html中img标签宽高相等?
本文介绍了css - 如何设置html中img标签宽高相等?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
如题所述,希望大家不吝赐教
解决方案
题主,这应该是你要的,无论图片大小尺寸如何,都变成正方形
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="rubine">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
<style type="text/css">
.img-wrap{
width: 60%; /* 这里设置占屏幕宽度百分比 */
margin: 0 auto;
}
/* 创建一个正方形容器 */
.img-container{
width: 100%;
height: 0px;
padding-bottom: 100%;
overflow:hidden;
margin: 0;
position:relative;
}
/* 采用绝对定位 */
.img-wrap img{
position:absolute;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div class='img-wrap'>
<div class="img-container">
<img src="3.png" />
</div>
</div>
</body>
</html>
这篇关于css - 如何设置html中img标签宽高相等?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文