2016-08-04 102 views
1

我有一個HTML頁面,我已經把背景圖像放入正文css中。如何讓我的圖像在HTML頁面中相對於背景圖像保持固定位置?

body { 
    /*cursor: URL("target.png"),pointer;*/ 
    background-color:#202020; 
    background-image: url('../Images/BGimage.png'); 
    background-repeat: no-repeat; 
    background-size: contain; 
    background-position: center center; 
} 

現在,當我把一個新的形象在HTML頁面中說,

<img src="target.png" style="position:absolute;margin-top:280px;margin-left:700px;z-index:1" /> 

,當我去全屏幕或最小化window.The背景圖像是固定的,但新的圖像圖像的位置變化轉變。我該如何解決這個問題?

+0

圖像應該保持與背景圖像上相對位置的相對位置嗎? – Aaron

+0

你需要使用剩餘百分比,頂部和變換屬性。 – Aaron

+0

@Ritesh這樣的事情? https://jsfiddle.net/LeoLion/dd8k66yj/ –

回答

-1

你可以試試position:fixed css style。無論您最大化還是最小化屏幕,這都會修復您的照片。

style{ 
    position:fixed; 
    margin-top:280px; 
    margin-left:700px; 
} 

希望它會有所幫助。

+0

由此,如果用戶將調整窗口大小,他將無法看到圖像..什麼是解決方案! –

0
<img src="target.png" style="position:absolute;top:280px;left:700px;z-index:1" /> 

使用上邊和左邊你可以設置的位置水平和垂直圖像的話,就不會移動,因爲它是在像素那個位置。

0

如果你想要一個較小的圖像覆蓋一個非重複的背景圖像相對於背景圖像永久固定的位置,那麼你可能只需在圖像編輯應用程序中打開背景圖像,複製並粘貼將較小的圖像放入畫布中,按您想要的方式進行定位,然後將其保存爲新的圖像文件。然後,您可以使用該新圖像文件作爲背景圖像。

當然,如果您需要在頁面生命週期中對較小的圖像應用動態更改(如過渡或對其CSS的動態更改),則此功能無效。但否則,我會認爲這將是最好的解決方案。


我仔細看過這個問題。由於您需要對較小圖像進行動態更改,因此將其嵌入到背景圖像中將不起作用。相反,有必要計算並指定包含元素中較小圖像的確切位置,以便將背景圖像疊加在所需的確切位置。

要完成此任務,有必要確定背景圖像相對於包含元素的最終絕對位置。


CSS屬性值序列

明白,CSS屬性值經歷一個複雜的計算處理,其可以結合的瀏覽器的默認值,CSS源聲明,特異性,繼承,相互依存的屬性的相互作用,這是非常重要的依賴於版圖的相對值的分辨率,以及某些情況下的舍入/近似值。

我們可以通過這個計算序列中,列出了可以發揮作用價值觀的不同階段總結這一過程:

initial value作爲瀏覽器默認的根元素。還用作非繼承屬性的非根元素的瀏覽器默認值(繼承屬性可以繼承根或父級的初始值(如果未在其譜系或自定義風格中進行超集)。

source value在文檔的源文件中明確指定的值(文件鏈接,樣式標籤和內聯樣式屬性)。這考慮了CSS的級聯規則,爲元素/僞元素選擇最具體的規則。

specified value如果給定源值,否則爲繼承的值(用於繼承的屬性)或初始值(用於非繼承的屬性)。請注意,源值本身可能被設置爲文字空白字inheritinitial

computed value從指定的值解析inheritinitial獲得更多的具體值,再加上額外的應用轉換,如跨度position:absolute更改爲display:block推導。預先佈局。

used value完成所有計算後的最終值。後佈局。解決自動和絕對像素值的百分比。

actual value已應用所有近似值後的使用值。例如,用戶代理可能只能渲染具有整數像素值的邊框,並可能被迫近似計算出的邊框寬度。


令人困惑的是,在getComputedStyle()功能確實回報計算的值,而是返回一些所謂的解析值:

resolved value通過getComputedStyle()返回。 (1)對於line-height,它始終是使用的值。 (2)否則,對於使用display:none的元素/僞元素(a),或(b)該屬性永遠不適用的元素/僞元素(a),或(c)對於過度限制的bottomleftrighttop,總是計算出的值(因爲在大多數情況下,它們的佈局不能確定)。 (3)否則,對於bottom,left,right,top,width,height,paddingmargin屬性,它總是使用的值。 (4)否則,它總是計算值。


的問題

的問題是,我們需要的背景圖像的位置。背景圖像本身不是一個元素,因此我們無法從CSS使用的值中獲取它的位置,因爲它沒有自己的CSS值。此外,由於背景圖像放置的複雜性,其精確位置可以從其包含元素的位置以微妙的方式變化,取決於(1)background-origin,background-sizebackground-position的值,(2)原始背景圖像大小, (3)包含元素大小,其本身可以取決於用戶的瀏覽器窗口的大小,其可以動態改變。

當然,上述三種CSS屬性的值的排列組合會固定相對於其包含元素的背景圖像,並且允許我們靜態地確定將較小圖像置於無論有沒有其他細節,都需要相對於背景圖像的位置。但對於你的情況,因爲你有background-size:containbackground-position:center center,這裏不適用。

在一般情況下,我們需要根據包含元素的上述三個CSS屬性以及包含元素的其他CSS屬性(特別是padding和,對於案例動態地計算背景圖像的位置background-origin:border-box,邊框),原始圖像大小和包含的元素大小。


的解決方案需要一個JavaScript函數來計算在該含元素的背景圖像的位置。

請注意,我一直在使用術語「背景位置」在目標計算的描述中有點鬆散,但應該澄清的是,爲了計算較小圖像的所需位置,我們需要計算兩者左上角的背景圖片的右下角。換句話說,我們需要確定背景圖像的整個邊界框,以便能夠計算背景圖像中我們希望放置較小圖像的目標位置的座標。

爲什麼getComputedStyle().backgroundPosition不能直接

使用你可能會認爲,我們應該能夠得到背景圖像的最終絕對位置getComputedStyle().backgroundPosition包含的元素上運行。這是不正確的。原因是我們需要最後的使用的值爲的背景圖像位置。如前所述,getComputedStyle()僅爲少數CSS屬性返回已使用的值,即使只在某些情況下也是如此,而backgroundPosition不在其中。另外,正如前面所解釋的,我們還需要背景圖像的右下角,而backgroundPosition只會返回左上角。我們也可以通過得到getComputedStyle().backgroundSize來得到右下角,但是backgroundSize遭受與backgroundPosition相同的限制,因爲它只會給我們計算出的值而不是用過的值。

瀏覽器API解決方案

我簡單搜索的結果可以用來獲得上述兩個CSS屬性的使用值在瀏覽器的API的規定,但不幸的是有沒有出現任何。請參閱Is there a cross-browser method of getting the used css values of all properties of all elements?,它不能令人滿意地回答該問題,並且沒有一個會話似乎知道解析值的概念,並且getComputedStyle()函數在大多數情況下返回計算值。

現有的JavaScript解決方案

我做了一些搜索,看是否有人已經想出了一個JavaScript的解決這個問題。最接近的似乎是Get final size of background image中給出的JavaScript函數。不幸的是,該功能僅計算背景圖像的大小,所以它是不夠的。 (我認爲它不適用於所有情況,但我沒有證實這一點。)

解決方案

所以,我寫我自己的JavaScript函數來解決這個問題。

回想一下,getComputedStyle().backgroundPositiongetComputedStyle.backgroundSize不給我們這兩個屬性的最終使用值;他們只給我們計算價值。但是這些計算值爲我們提供了一個必要的出發點,以手動計算符合標準的瀏覽器在佈置包含元素及其背景圖像時將使用的值。因此,在我的函數中,我得到了上述兩個計算值以及getComputedStyle().backgroundOrigin,以及填充和邊框CSS值,並繼續計算適合當前值的背景圖像的邊界框。我們必須處理backgroundOrigin的所有三個可能值,backgroundPosition的百分比和絕對像素值以及backgroundSize的百分比絕對像素值autocovercontain

下面我將該功能作爲完整工作演示的一部分。我走了一會兒,找到了一幅地球圖片作爲背景圖片,一張國際空間站的圖片,對於較小的圖片具有透明度,在背景圖片中定義了三個不同的位置,指定爲寬度和高度的百分比,並提供(1)在三個不同位置之間轉換和(2)動態調整包含元素的大小的控件,觸發較小的圖像重新計算其所需的絕對像素位置,以便保留在背景圖像內的當前選定位置。

window.getBackgroundImageBox = function(elem,i) { 
 
    // elem -- the element that instantiates the background image 
 
    // i -- the index into the list of background images set in the CSS 
 

 
    // there are 8 specific CSS background properties: 
 
    // 
 
    // background-image: assume this is set to an image URL 
 
    // background-position: will get resolved value, must calculate used value 
 
    // background-size: will get resolved value, must calculate used value 
 
    // background-repeat: assume this is set to no-repeat 
 
    // background-origin: must take this into account when determining pos and size 
 
    // background-clip: can ignore this; only clips, doesn't change actual image pos and size 
 
    // background-attachment: assume either scroll (default), or fixed with no scrolling, so ignore this 
 
    // background-color: not relevant to pos and size 
 

 
    // default i if not given 
 
    if (i === undefined) i = 0; 
 

 
    // get resolved origin, size, and pos 
 
    let computedStyle = getComputedStyle(elem); 
 
    let resolvedOrigin = computedStyle.backgroundOrigin.split(', ')[i]; 
 
    let resolvedSize = computedStyle.backgroundSize.split(', ')[i]; 
 
    let resolvedPos = computedStyle.backgroundPosition.split(', ')[i]; 
 
    // get resolved elem width and height 
 
    let resolvedWidth = computedStyle.width.split(', ')[i]; 
 
    let resolvedHeight = computedStyle.height.split(', ')[i]; 
 
    let elemWidth = parseInt(resolvedWidth.replace('px',''),10); 
 
    let elemHeight = parseInt(resolvedHeight.replace('px',''),10); 
 
    // get resolved border sizes 
 
    let borderLeft = !computedStyle.borderLeftWidth ? 0 : parseInt(computedStyle.borderLeftWidth.replace('px',''),10); 
 
    let borderTop = !computedStyle.borderTopWidth ? 0 : parseInt(computedStyle.borderTopWidth.replace('px',''),10); 
 
    let borderRight = !computedStyle.borderRightWidth ? 0 : parseInt(computedStyle.borderRightWidth.replace('px',''),10); 
 
    let borderBottom = !computedStyle.borderBottomWidth ? 0 : parseInt(computedStyle.borderBottomWidth.replace('px',''),10); 
 
    // get resolved padding sizes 
 
    let paddingLeft = !computedStyle.paddingLeft ? 0 : parseInt(computedStyle.paddingLeft.replace('px',''),10); 
 
    let paddingTop = !computedStyle.paddingTop ? 0 : parseInt(computedStyle.paddingTop.replace('px',''),10); 
 
    let paddingRight = !computedStyle.paddingRight ? 0 : parseInt(computedStyle.paddingRight.replace('px',''),10); 
 
    let paddingBottom = !computedStyle.paddingBottom ? 0 : parseInt(computedStyle.paddingBottom.replace('px',''),10); 
 

 
    // derive actual bounding box, which could be different from content box due to origin 
 
    let byOriginLeft; 
 
    let byOriginTop; 
 
    let byOriginRight; 
 
    let byOriginBottom; 
 
    if (resolvedOrigin === 'content-box') { 
 
    byOriginLeft = paddingLeft; 
 
    byOriginTop = paddingTop; 
 
    byOriginRight = paddingLeft+elemWidth; 
 
    byOriginBottom = paddingTop+elemHeight; 
 
    } else if (resolvedOrigin === 'padding-box') { 
 
    byOriginLeft = 0; 
 
    byOriginTop = 0; 
 
    byOriginRight = paddingLeft+elemWidth+paddingRight; 
 
    byOriginBottom = paddingTop+elemHeight+paddingBottom; 
 
    } else if (resolvedOrigin === 'border-box') { 
 
    byOriginLeft = -borderLeft; 
 
    byOriginTop = -borderTop; 
 
    byOriginRight = paddingLeft+elemWidth+paddingRight+borderRight; 
 
    byOriginBottom = paddingTop+elemHeight+paddingBottom+borderBottom; 
 
    } else { 
 
    throw 'unsupported origin: '+resolvedOrigin; 
 
    } // end if 
 
    let byOriginWidth = byOriginRight-byOriginLeft; 
 
    let byOriginHeight = byOriginBottom-byOriginTop; 
 

 
    // create image object to get original image's size 
 
    let image = new Image(); 
 
    image.src = computedStyle.backgroundImage.split(', ')[i].replace(/url\((['"])?(.*?)\1\)/gi,'$2').replace(/\\(.)/,'$1'); // note: don't have to decode URI to assign, but must manually strip backslash escape codes 
 
    let imageWidth = image.width; 
 
    let imageHeight = image.height; 
 

 
    // get original image y/x ratio, and elem y/x ratio 
 
    let imageRatio = imageHeight/imageWidth; 
 
    let elemRatio = elemHeight/elemWidth; 
 

 
    // compute initial idea of the result based on origin and size; will apply position afterward 
 
    if (resolvedSize === 'cover') { 
 

 
    if (elemRatio > imageRatio) { // more height in elem than image => flush height, surplus width 
 
     res = { 
 
     'left':byOriginLeft, 
 
     'top':byOriginTop, 
 
     'right':byOriginLeft+byOriginHeight/imageRatio, 
 
     'bottom':byOriginBottom 
 
     }; 
 
    } else { // more width in elem than image => flush width, surplus height 
 
     res = { 
 
     'left':byOriginLeft, 
 
     'top':byOriginTop, 
 
     'right':byOriginRight, 
 
     'bottom':byOriginTop+byOriginWidth*imageRatio 
 
     }; 
 
    } // end if 
 

 
    } else if (resolvedSize === 'contain') { 
 

 
    if (elemRatio > imageRatio) { // more height in elem than image => flush width, deficient height 
 
     res = { 
 
     'left':byOriginLeft, 
 
     'top':byOriginTop, 
 
     'right':byOriginRight, 
 
     'bottom':byOriginTop+byOriginWidth*imageRatio 
 
     }; 
 
    } else { // more width in elem than image => flush height, deficient width 
 
     res = { 
 
     'left':byOriginLeft, 
 
     'top':byOriginTop, 
 
     'right':byOriginLeft+byOriginHeight/imageRatio, 
 
     'bottom':byOriginBottom 
 
     }; 
 
    } // end if 
 

 
    } else { 
 

 
    // parse size into width and height values 
 
    let resolvedSizeSplit = resolvedSize.split(' '); 
 
    let resolvedSizeWidth = resolvedSizeSplit[0]; 
 
    let resolvedSizeHeight = resolvedSizeSplit.length >= 2 ? resolvedSizeSplit[1] : 'auto'; // resolved always has both in FF, but not IE 
 

 
    // resolve to integer width and height values 
 
    let sizeWidth; 
 
    let sizeHeight; 
 
    if (resolvedSizeWidth === 'auto' && resolvedSizeHeight === 'auto') { 
 
     // double auto uses original img size 
 
     sizeWidth = imageWidth; 
 
     sizeHeight = imageHeight; 
 
    } else { 
 
     // if not double auto, calculate non-auto first, then resolve auto if exists 
 
     if (resolvedSizeWidth !== 'auto') { 
 
     if (resolvedSizeWidth.indexOf('%') > -1) { 
 
      let sizeWidthPct = parseInt(resolvedSizeWidth.replace('%','')); 
 
      sizeWidth = sizeWidthPct*byOriginWidth/100; 
 
     } else { 
 
      sizeWidth = parseInt(resolvedSizeWidth.replace('px','')); 
 
     } // end if 
 
     } // end if 
 
     if (resolvedSizeHeight !== 'auto') { 
 
     if (resolvedSizeHeight.indexOf('%') > -1) { 
 
      let sizeHeightPct = parseInt(resolvedSizeHeight.replace('%','')); 
 
      sizeHeight = sizeHeightPct*byOriginHeight/100; 
 
     } else { 
 
      sizeHeight = parseInt(resolvedSizeHeight.replace('px','')); 
 
     } // end if 
 
     } // end if 
 
     // resolve dependent auto 
 
     if (resolvedSizeWidth === 'auto') sizeWidth = sizeHeight/imageRatio; 
 
     if (resolvedSizeHeight === 'auto') sizeHeight = sizeWidth*imageRatio; 
 
    } // end if 
 

 
    res = { 
 
     'left':byOriginLeft, 
 
     'top':byOriginTop, 
 
     'right':byOriginLeft+sizeWidth, 
 
     'bottom':byOriginTop+sizeHeight 
 
    }; 
 

 
    } // end if 
 

 
    // get absolute pos value in pixels 
 
    let resolvedPosSplit = resolvedPos.split(' '); 
 
    let resolvedPosLeft = resolvedPosSplit[0]; 
 
    let resolvedPosTop = resolvedPosSplit.length >= 2 ? resolvedPosSplit[1] : '50%'; // resolved always has both in FF, but not IE 
 
    let posLeft; 
 
    let isPosLeftPct; 
 
    if (resolvedPosLeft.indexOf('%') > -1) { 
 
    isPosLeftPct = true; 
 
    let posLeftPct = parseInt(resolvedPosLeft.replace('%','')); 
 
    posLeft = posLeftPct*(byOriginWidth-(res.right-res.left))/100; 
 
    } else { 
 
    isPosLeftPct = false; 
 
    posLeft = parseInt(resolvedPosLeft.replace('px','')); 
 
    } // end if 
 
    let posTop; 
 
    let isPosTopPct; 
 
    if (resolvedPosTop.indexOf('%') > -1) { 
 
    isPosTopPct = true; 
 
    let posTopPct = parseInt(resolvedPosTop.replace('%','')); 
 
    posTop = posTopPct*(byOriginHeight-(res.bottom-res.top))/100; 
 
    } else { 
 
    isPosTopPct = false; 
 
    posTop = parseInt(resolvedPosTop.replace('px','')); 
 
    } // end if 
 

 
    // apply pos 
 
    // tricky: must *not* apply pct pos adjustment to flush dimension for cover and contain 
 
    if (!(
 
    isPosLeftPct && (
 
     resolvedSize === 'cover' && elemRatio < imageRatio 
 
     || resolvedSize === 'contain' && elemRatio > imageRatio 
 
    ) 
 
)) { 
 
    res.left += posLeft; 
 
    res.right += posLeft; 
 
    } // end if 
 
    if (!(
 
    isPosTopPct && (
 
     resolvedSize === 'cover' && elemRatio > imageRatio 
 
     || resolvedSize === 'contain' && elemRatio < imageRatio 
 
    ) 
 
)) { 
 
    res.top += posTop; 
 
    res.bottom += posTop; 
 
    } // end if 
 

 
    return res; 
 

 
}; 
 

 
// global constants 
 
var SMALLERIMAGE_LEFTPCT = [67,90,15]; 
 
var SMALLERIMAGE_TOPPCT = [64,10,70]; 
 
var MULT = 1.2; 
 

 
// global variables 
 
var g_pctIndex = 0; 
 

 
// state change functions 
 
window.updateSmallerImage = function() { 
 

 
    let leftPct = SMALLERIMAGE_LEFTPCT[g_pctIndex]; 
 
    let topPct = SMALLERIMAGE_TOPPCT[g_pctIndex]; 
 

 
    // get the smaller image element and its containing element 
 
    let smallerImageElem = document.getElementById('smallerImage'); 
 
    let containingElem = smallerImageElem.parentElement; 
 

 
    // get the bounding box of the background image in the containing element 
 
    let bgbox = getBackgroundImageBox(containingElem); 
 

 
    // get the computed style of the smaller image element 
 
    let computedStyle = getComputedStyle(smallerImageElem); 
 

 
    // move the smaller image to the required position 
 
    // note: subtracting half the width and height for centering, but could do it differently 
 
    // must use computedStyle for the subtraction in case the inline style attribute has not been set yet 
 
    smallerImageElem.style.left = (bgbox.left + (bgbox.right-bgbox.left)*leftPct/100 - computedStyle.width.replace('px','')/2)+'px'; 
 
    smallerImageElem.style.top = (bgbox.top + (bgbox.bottom-bgbox.top)*topPct/100 - computedStyle.height.replace('px','')/2)+'px'; 
 

 
    // ensure the smaller image is displayed 
 
    smallerImageElem.style.display = 'block'; 
 

 
}; 
 

 
window.multContainingElementDim = function(prop,mult) { 
 
    let containingElem = document.getElementById('containingElement'); 
 
    let computedStyle = getComputedStyle(containingElem); 
 
    containingElem.style[prop] = (computedStyle[prop].replace('px','')*mult)+'px'; 
 
}; 
 

 
window.advanceSmallerIndexPctIndex = function() { 
 
    g_pctIndex = (g_pctIndex+1)%SMALLERIMAGE_LEFTPCT.length; 
 
    let indexButton = document.getElementById('indexButton'); 
 
    indexButton.value = '['+g_pctIndex+']'; 
 
    updateSmallerImage(); 
 
}; 
 

 
window.onload = function() { 
 
    updateSmallerImage(); 
 
    let containingElem = document.getElementById('containingElement'); 
 
    containingElem.addEventListener('transitionend',updateSmallerImage,false); 
 
};
#containingElement { 
 
    position:relative; 
 
    background-color:#202020; 
 
    background-image:url('http://media.zenfs.com/en_US/News/BGR_News/planet-earth.jpg'); 
 
    background-repeat:no-repeat; 
 
    background-size:contain; 
 
    background-position:center center; 
 
    width:500px; 
 
    height:400px; 
 
    transition: 
 
    width 0.3s ease-in-out, 
 
    height 0.3s ease-in-out; 
 
} 
 

 
#smallerImage { 
 
    position:absolute; 
 
    width:80px; 
 
    height:32px; 
 
    display:none; /* will show after positioning */ 
 
    transition: 
 
    left 0.3s ease-in-out, 
 
    top 0.3s ease-in-out; 
 
} 
 

 
#controls { 
 
    position:fixed; 
 
    left:0; 
 
    top:0; 
 
    z-index:1; 
 
}
<div id="controls"> 
 
    <input type="button" value="▲" onclick="multContainingElementDim('height',1/MULT);"/> 
 
    <input type="button" value="◄" onclick="multContainingElementDim('width',1/MULT);"/> 
 
    <input type="button" value="►" onclick="multContainingElementDim('width',MULT);"/> 
 
    <input type="button" value="▼" onclick="multContainingElementDim('height',MULT);"/> 
 
    &nbsp; 
 
    <input id="indexButton" type="button" value="[0]" onclick="advanceSmallerIndexPctIndex();"/> 
 
</div> 
 

 
<div id="containingElement"> 
 
    <img id="smallerImage" src="http://freepngimages.com/wp-content/uploads/2015/12/international-space-station-transparent-background.png"/> 
 
</div>

測試

我在Firefox非常徹底的測試主要實現功能getBackgroundImageBox(),試圖爲上述三個屬性810個不同的排列,它完美地工作爲他們所有。我在Chrome和Internet Explorer中進行了更少的徹底檢查。所有檢查均在Chrome中運行,但不幸的是,Internet Explorer在兩種情況下都失敗了,這似乎是因爲它爲getComputedStyle().backgroundSize返回的值對於那些失敗的案例而言是不正確的。我還沒有找出失敗的原因,或者如果有可能的解決方法,請注意這個問題。

這就是說,對於你的特定的CSS,一切似乎工作。主要實現功能以及整個演示似乎都基於我在所有Firefox,Chrome和Internet Explorer中的測試而工作。

+0

我需要應用動態更改。你有什麼解決方案嗎? –

+0

你需要申請什麼樣的動態變化? – bgoldst

+0

我需要將背景圖像上方的圖像動畫到背景圖像上的新位置。 –

1

即使在調整大小模式下,也要修正圖像的位置:相對於父母(在您的情況下,身體標記)。所以簡單給position;relative身體標記,你就完成了。

here

更新HTML

<img src="target.png" style="position:absolute;margin-top:280px;right:70px;z-index:1" /> 

更新CSS

body { 
    /*cursor: URL("target.png"),pointer;*/ 
    background-color:#202020; 
    background-image: url('../Images/BGimage.png'); 
    background-repeat: no-repeat; 
    background-size: contain; 
    background-position: center center; 
    position:relative; 
} 
+0

我以爲一樣,但它不工作。問題是背景圖像重新調整大小,因爲它本質上是有反應的。現在,由於重新調整大小,原始圖像相對於身體標記而不是背景圖像發生變化。 –

+0

這是我的原始css代碼: - html, body { height:100%; } body { background-image:url('Images/BGimage.png'); background-repeat:no-repeat; background-size:contains; background-position:center center; /* background-attachment:fixed; */ } –

+0

這是我的原始css代碼: - –

0

你可以嘗試保證金百分比,而不是像素

+0

試過了,不起作用!!!!! –

+0

保證金比例導致相同類型的問題。 –