我在CSS中重新调整背景图像的大小以适应其他比笔记本电脑屏幕尺寸更小的屏幕时遇到了问题
我已经尝试过'background-size: contain‘和'background-repeat : no-repeat’。尽管如此,背景图像还是变得不成比例。我有一组图像参数,它是'height: 100vh;‘
/* with this, only a fraction of image is seen in phone */
header {
    background - image: -webkit - linear - gradient(rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.7)), url(img / hero.jpg);
    background - image: linear - gradient(rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.7)), url(img / hero.jpg);
    background - size: cover;
    height: 100 vh;
    background - position: center;
    background - repeat: no - repeat;
    background - attachment: fixed;
}
/* with this a grey background appears in phone screens */
header {
    background - image: -webkit - linear - gradient(rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.7)), url(img / hero.jpg);
    background - image: linear - gradient(rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.7)), url(img / hero.jpg);
    background - size: contain;
    height: 100 vh;
    background - position: center;
    background - repeat: no - repeat;
    background - attachment: fixed;
}我希望图像适合所有屏幕尺寸,而不会放大和模糊,但结果总是不成比例。
发布于 2019-05-26 15:39:56
我的代码也有同样的问题,我只添加了一行:
.your-class {
height: 100vh;
    }vh是视口高度。这将自动缩放以适合设备的浏览器窗口。
点击此处查看更多信息:How to make a div 100% height of the browser window?
https://stackoverflow.com/questions/56311314
复制相似问题