https://blog.csdn.net/coslay/article/details/47109281
騰訊微博和QQ空間的登錄背景圖片是根據訪客的屏幕大小自動縮放的,但是好像是用JQuery代碼實現的。先不說要調用jq庫拖慢了網頁的打開時間,而且對於兼用性不好。
前幾天用CSS研究出相同效果的樣式代碼。無論圖片多大都能根據屏幕變化(當然圖片尺寸越大越好)。而且在拉動網頁窗體大小時會自動調節圖片大小,實時交互。效果上圖看不了。在這里放個連接,
CSS 代碼如下:
#background { position: fixed; top: 0; left: 0; width: 100%; height: 100%; overflow: hidden; background-color: #211f1f; display:none\8; } #background .bg-photo { position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: none; overflow: hidden; -webkit-background-size: cover !important; -moz-background-size: cover !important; -o-background-size: cover !important; background-size: cover !important; } #background .bg-photo-1 { background: url('../image/alone.jpg') no-repeat center center; } #background-ie { position: fixed; top: 0; left: 0; width: 100%; height: 100%; overflow: hidden; background-color: #211f1f; }
HTML代碼如下:
<div id="background"> <div class="bg-photo bg-photo-1" style="display: block;"></div> </div>
