我有一个像这样的图片标签
.flexD {
display: flex;
margin: 0 auto;
width: 90%;
}
.flexP {
display: flex;
}
.imgInP {
margin: auto 0;
}<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title></title>
</head>
<body>
<div class="flexD">
<picture class="flexP">
<!-- I do have some source tags-->
<img src="http://placehold.it/100x80"> </picture>
<p> content content content content content content content content content content content content content content content content content content</p>
</div>
<!-- I am using this code-->
<div class="flexD">
<picture class="flexP">
<!-- I do have some source tags-->
<img class = "imgInP" src="http://placehold.it/100x80"> </picture>
<p> content content content content content content content content content content content content content content content content content content</p>
</div>
</body>
</html>
在Chrome上,代码看起来像下面的图片,但在Edge上,我的图片被拉伸了,就像上面的一样。这是否意味着我的边距:自动0;在Edge上不起作用?我该如何解决这个问题呢?
发布于 2020-03-26 19:45:29
如果我对您的需求的理解是正确的,请查看以下内容:
如果您认为image正在被拉伸,那么您可以使用与content:url相同的图像,并指定height和width,以便它在不同的浏览器中保持一致。
.flexD {
display: flex;
margin: 0 auto;
width: 90%;
}
.flexP {
display: flex;
}
.imgInP {
content: url(http://placekitten.com/301/301);
width: 100px;
height: 80px;
}<body>
<div class="flexD">
<picture class="flexP">
<!-- I do have some source tags-->
<img class="imgInP">
</picture>
<p> content content content content content content content content content content content content content content content content content content</p>
</div>
<!-- I am using this code-->
<div class="flexD">
<picture class="flexP">
<!-- I do have some source tags-->
<img class="imgInP"> </picture>
<p> content content content content content content content content content content content content content content content content content content</p>
</div>
</body>
发布于 2020-03-26 20:13:53
你可以使用css的object-fit属性,它可以阻止图像被拉伸。
.imgInP{
object-fit: cover;
}https://stackoverflow.com/questions/60865614
复制相似问题