javascript
  • css
  • 2015-11-06 60 views -2 likes 
    -2

    Image你能幫我最大化我的圖像背景嗎?

    我使用這個document.style

    document.body.style.backgroundImage = "url('okeball-HD.png')"; 
        document.body.style.backgroundPosition = '100% 100%'; 
        document.body.style.backgroundRepeat = 'no-repeat'; 
        document.body.style.backgroundSize = 'cover'; 
    
    +2

    問題尋求幫助的代碼必須包括必要的重現它最短的代碼**在問題本身** 。請參閱[**如何創建一個最小,完整和可驗證示例**](http://stackoverflow.com/help/mcve) –

    +0

    @Carlo:如果您有解決方案,您應該接受幫助您的答案。 –

    回答

    0

    CSS技巧告訴你如何做到這一點: https://css-tricks.com/perfect-full-page-background-image/

    有幾個不同的方法可以做到這一點。

    設置一個div的圖像:

    <div id="bg"> 
        <img src="okeball-HD.png" alt=""> 
    </div> 
    

    然後設置樣式:

    #bg { 
        position: fixed; 
        top: -50%; 
        left: -50%; 
        width: 200%; 
        height: 200%; 
    } 
    #bg img { 
        position: absolute; 
        top: 0; 
        left: 0; 
        right: 0; 
        bottom: 0; 
        margin: auto; 
        min-width: 50%; 
        min-height: 50%; 
    } 
    
    +0

    謝謝卡爾它的作品!非常感謝! – Carlo

    +0

    如果這有幫助,你能接受我的答案嗎?謝謝。 –

    相關問題