<分区>
我找不到能够占据整个页面宽度且仅占页面高度 25% 的图片。一旦我更改了图像的 css,它看起来很奇怪,因为它的宽度与高度相比太大了。有人知道我在哪里可以找到适用于此的图像吗?或者我应该如何处理?
提前谢谢你,
最佳答案
您有很多方法可以解决这个问题。一个简单的方法是使用 background-image
属性而不是 <img>
标签。
例如:
div.image {
background-image: url('your/img/path.jpg');
background-repeat: no-repeat;
background-size: cover (will cover all the div surface) || contain (will fully contains your image);
}
fiddle :
div.image {
display: block;
width: 100%;
height: 50vh;
background-image: url('http://musiccitiessummit.com/wp-content/uploads/chicago-1.jpg');
background-repeat: no-repeat;
background-size: cover;
background-position: center center;
}
<div class="image"></div>
编辑
如果您必须使用 <img>
标签,看看这个object-fit
属性(property):https://css-tricks.com/almanac/properties/o/object-fit/
关于css - 查找占据所有宽度但仅占页面高度 25% 的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45635548/