0

我試圖弄清楚製作背景圖像的最佳方法 - 完全響應 - 到目前爲止,我可以找出的最佳方法是使用背景大小:封面,因爲大多數人往往會建議,但背景-attachment:固定的,以便圖像在屏幕大小調整時按比例縮小,否則它會保留原來的比例並且不會縮放。使用只是背景大小:覆蓋拉伸圖像以填充容器div,但不會自動縮放比例。無背景附件縮放背景圖片:固定?

但是,我不希望在向下滾動時隱藏圖像部分的固定背景效果並希望它是後臺附件:滾動,但我不能得到那個工作也使它擴展。

所以我的問題是:有什麼辦法我不知道有背景圖像自動縮放與屏幕大小,而不必使用background-attachment:fixed來實現它?

請參閱我的jsfiddle什麼我此刻有:https://jsfiddle.net/uhoL5d5w/2/

(是的,我也知道我將需要使用媒體查詢在某些時候起到優化圖像的各種屏幕尺寸)

我當前的代碼看起來像:

<header> 
    <div class="launch-bg"> 
     <nav class="menu"> 
     </nav> 
    </div> 
</header> 

<div class="page-wrapper"> 

</div> 


<div class="push"></div> 

<!-- Footer --> 

<div class="footer"></div> 


html, 
body { 
    @include box-sizing(border-box); 
    height: 100%; 
} 

div, 
body { 
    margin: 0; 
    padding: 0; 
} 

body { 
    display: block; 
    background-color: #000000; 
} 

.page-wrapper { 
    margin: 0 auto -900; 
    min-height: 100%; 
    height: auto; 
} 


* { 
    margin: 0; 
    padding: 0; 
} 


header { 
    display: block; 
    width: 100%; 
    height: 1200px; 
} 

    .launch-bg { 
    height: 1200px; 
    background-image: url('http://s8.postimg.org/56xlj2rc5/launch_bg.jpg'); 
    background-repeat: no-repeat; 
    background-attachment: fixed; 
    background-position: center center; 
    background-size: cover; 
    } 

.footer { 
    height: 900px; 
    padding: 6% 0; 
    color: $white; 
    background-image: url('http://s8.postimg.org/onib5lmg5/footer_bg.jpg'); 
    background-repeat: no-repeat; 
    background-attachment: fixed; 
    background-position: center center; 
    background-size: cover; 
} 
+0

background-attachment的初始值是滾動 - 它不需要聲明。這就像是說:'div {display:block; }'此外,'background-size'不會(並且不會)適用於任何'background-attachment:fixed'。相關:http://stackoverflow.com/questions/21786272/css-background-size-cover-background-attachment-fixed-clipping-background-im – Adam

回答

0

這裏有一個簡單的例子,我想,你問什麼的,只是修剪了這一切爲清楚:

header { 
    display: block; 
    width: 100%; 
    height: 1200px; 
    background-image: url('http://s8.postimg.org/56xlj2rc5/launch_bg.jpg'); 
    background-repeat: no-repeat; 
    background-attachment: scroll; 
    background-position: center center; 
    background-size: cover; 
} 
+0

'background-attachment:scroll'是多餘的 - 'scroll'已經是在CSS中用於'background-attachment'的初始值 – Adam

+0

我將它包含在內以確保他不會使用固定值或其他值,就像他的小提琴一樣。但仍然很好指出。 –

+0

不幸的是,這不是我正在尋找...這擴大了圖像太多(它不適合在我的屏幕上),它不再縮放...正如我所說我已經嘗試使用background-attachment:scroll與封面屬性... – FuManchuNZ