背景图像的垂直高度

时间:2016-11-21 15:14:43

标签: html css position background-image

我有情况。我使用标题全宽图像,因此宽度为100%,高度I已固定为650px。 我需要定位图像,以防万一我增加或减少浏览器宽度,背景图像只会增加或减少宽度,而不是垂直移动图像。

我希望我认为这是可以理解的。如果没有,请点击此处截图

现状

enter image description here

我想要的情况

enter image description here

SCSS代码

header {
    margin-top: 78px;
    background-repeat: no-repeat;
    background-position: center;
    background-size: cover;
    position: relative;
    max-width: calc(100% - 120px);
}

.header-main {
    background-image:url(../img/header.jpg);
    height: 650px;
    margin-left: 60px;
    margin-right: 60px;
}

HTML

<header class="header-main" >
        ---Content---
</header>

非常感谢你:)

1 个答案:

答案 0 :(得分:1)

尝试更改背景尺寸

header {
    margin-top: 78px;
    background-repeat: no-repeat;
    background-position: center;
    background-size: auto 650px;
    position: relative;
    max-width: calc(100% - 120px);
}

.header-main {
    background-image:url(../img/header.jpg);
    height: 650px;
    margin-left: 60px;
    margin-right: 60px;
}
相关问题