<分区>
<分区>
这是我的第一个问题,所以如果我的问题可能不切题,请原谅。
在照片报道中,我有大约 30 张高分辨率图片,我通过 CSS 加载它们,因为我认为它可能比使用“img”标签具有速度优势。
这是 30 张图片之一的代码:
.image-bg-fixed-height2 {
display: table;
width: 100%;
height: 100%;
padding: 10px 0;
text-align: center;
color: #fff;
background: url(../Snapshots/Adasevci_02.jpg) no-repeat center center scroll;
background-color: #000;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
-o-background-size: cover;
}
但是在 HTML 中,当我使用 CSS 中指定的“img”标签时,例如
img {
max-width: 100%;
height: auto;
padding: 10px 0;
}
使用 CSS 方法的图像和“img”的缩放比例不同。 “img”在移动设备上似乎被压缩了。我希望图片表现得像 CSS 类。
<aside class="image-bg-fixed-height2"></aside>
<img src="http://www.jagaland.de/moteladasevci/Snapshots/Adasevci_02.jpg" border="0" class="image-bg-fixed-height2" width="1920px" height="1080px" alt="This is the alt text 2">
它看起来很棒并且响应 CSS 方法,但我通过替代文本失去了 SEO 功能,这对我的照片报道来说是行不通的。
最佳答案
如果您使用 <img>
使用 CSS width:100%
或 max-width:100%;
然后它会自动挤压,这样你就可以管理它以响应删除 width:100%
至 auto
但最好的是你可以在后台 css 中使用它和 css background-size:cover;
关于CSS 背景图像的缩放比例与 <img> 不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35889610/