首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >当在手机和其他小屏幕上查看时,我的网站的背景图像变得不成比例

当在手机和其他小屏幕上查看时,我的网站的背景图像变得不成比例
EN

Stack Overflow用户
提问于 2019-05-26 14:46:54
回答 3查看 51关注 0票数 0

我在CSS中重新调整背景图像的大小以适应其他比笔记本电脑屏幕尺寸更小的屏幕时遇到了问题

我已经尝试过'background-size: contain‘和'background-repeat : no-repeat’。尽管如此,背景图像还是变得不成比例。我有一组图像参数,它是'height: 100vh;‘

代码语言:javascript
运行
复制
/* 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;
}

我希望图像适合所有屏幕尺寸,而不会放大和模糊,但结果总是不成比例。

EN

Stack Overflow用户

发布于 2019-05-26 15:39:56

我的代码也有同样的问题,我只添加了一行:

代码语言:javascript
运行
复制
.your-class {
height: 100vh;
    }

vh是视口高度。这将自动缩放以适合设备的浏览器窗口。

点击此处查看更多信息:How to make a div 100% height of the browser window?

票数 0
EN
查看全部 3 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56311314

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档