2017-02-11 127 views
0

我有一個包含背景圖像的div,我想要在右下角保持對齊狀態,但我希望圖像根據瀏覽器窗口的大小進行縮放。我目前擁有的是:根據屏幕尺寸縮放div格式的背景圖像

backgnd { 
    background: url(img/roneggler.png) no-repeat; 
    position: fixed; 
    bottom: 0px; 
    right: 0px; 
    width: 1000px; 
    height: 1000px; 
} 

我試圖在widthheight值設置爲100%但與div的位置打亂。此頁面的鏈接可以在這裏找到:http://inetgate.biz/ron.eggler/

回答

0

好吧,

我得到了它,現在,最終的解決方案是這樣的:

.backgnd { 
    background: url(img/roneggler.png) no-repeat; 
    background-size: contain; 
    background-position: right bottom; 
    position: absolute; 
    bottom: 0px; 
    right: 0px; 
    width: 100%; 
    height: 100%; 
} 

訣竅是T選用background-size: contain;,而不是cover拿不到圖像縮放了所有的在大屏幕上的方式。

0

CSS:

.container{ 
    width:100%; 
} 

你可以使用jQuery:

var w = $(window).width(); 
$('.content').css('width', w); 
1

您應該使用的背景大小:蓋,寬度和高度100% ;

backgnd { 
    background: url(img/roneggler.png) no-repeat; 
    position: absolute; 
    background-size: cover; 
    bottom: 0px; 
    right: 0px; 
    width: 100%; 
    height: 100%; 
} 
+0

如果我使用你的建議,圖像不是底部對齊的。 – cerr

+1

嘗試使用位置aboslute(而不是固定)..並最終設置適當的右下角位置 – scaisEdge

+0

是的,我正在使用'absolute',正如你上面所建議的。它看起來像div很好地縮放,但背景圖像不會保持'絕對'對齊div的右下角。我添加了一個臨時的'border:5px solid red;'爲了更好的描述事物 – cerr