簡體   English   中英

背景圖像縮放

[英]Background Image Zoom

我想將背景圖像添加到我正在換膚的網站的各個部分中。

問題是背景圖像被放大了。

見下文。

剛創建一個新的CSS div會更好,更快。請問有人可以提供語法建議嗎?

// Sections backgrounds

var pageSection = $(".home-section, .page-section, .small-section, .split-section");
pageSection.each(function(indx){

    if ($(this).attr("data-background")){
        $(this).css("background-image", "url(" + $(this).data("background") + ")");
    }
});

在此處輸入圖片說明

的CSS

background-size: cover

要么

background-size: 100%

應該是您的解決方案。

您可以稍微調整一下JavaScript來對部分進行分類。

var pageSection = $(".home-section, .page-section, .small-section, .split-section");
pageSection.each(function(){
    if ($(this).attr("data-background")){
        $(this).css("background-image", "url(" + $(this).data("background") + ")");
        $(this).addClass('full-background'); //adds the class
    }
});

然后使用CSS正確設置樣式

.full-background {
    background-size: cover;
 }

但是,這是CSS3樣式,因此請注意IE8

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM