2016-11-07 46 views
0

我有一個透明的背景圖像,我想爲它的背景添加灰色,我做到了,但是我無法擴展它的寬度以達到整個頁面的寬度(換句話說,我無法改變它的大小即使在使用背景大小的屬性之後)。爲什麼我無法增加添加到圖像的背景大小?

img{ 
 
    height:40px; 
 
    width:40px; 
 
    background-color:rgb(0, 0, 0); 
 
    background-size:100px 100px; 
 
}
<img src="https://www.google.co.in/search?espv=2&biw=1366&bih=662&tbm=isch&sa=1&q=html+logo+transparent+background&oq=html+logo+tra&gs_l=img.1.1.0j0i30k1.3420.4038.0.5941.4.4.0.0.0.0.302.302.3-1.1.0....0...1c.1.64.img..3.1.301.xRQ23nL94iw#imgrc=FkYJhNmbMb325M%3A" align="center">

+0

背景圖像,因爲你的元素的寬度/高度僅爲'40x X 40px' – Dekel

回答

0

變化的高度和寬度

img{ 
     height:100%; 
     width:100%; 
     } 
+0

它是圖像,我怎麼做? – KSJ10

+0

是的,它是img的風格嘗試改變40px到100% –

1

使用在父DIV

<style> 
     .parent { 
      width: 100%; 
      background-image:url('yourimage.jpg'); 
      background-position: center center; 
      background-color: grey; 
     } 
    </style> 

    <div class="parent"> 

    </div>