2017-02-27 88 views
0

我做了一些UI練習,並且背景圖像與身體標記有問題。圖像水平溢出,我想擺脫這一點。 Plz幫助我。身體背景溢出

代碼我試圖修復它。

<style type="text/css"> 
     body { 
      background: url("public/res/bg(WT).png") no-repeat fixed center center; 
      background-size: cover; 
     } 
    </style> 

問題說明:(紅色框)

enter image description here

我完整的代碼是一樣

<html> 
<head> 
<style> 
* { margin:0; padding:0; } 
body { 
      background: url("public/res/bg(WT).png") no-repeat fixed center center; 
      -webkit-background-size: cover; 
      -moz-background-size: cover; 
      -o-background-size: cover; 
      background-size: cover; 
     } 
</style> 
</head> 
<body> 
//contents are here 
</body> 
</html> 
+1

你可以把這個在plunkr?所以我們可以調試。因爲到目前爲止,我看到你的形象的問題。 CSS看起來不錯。 – Smit

+0

乍一看,它看起來問題不是來自背景圖像,而是來自一些邊緣 – Weedoze

+0

我爲所有標記0做了邊距和填充。@Weedoze –

回答

0

包裹之下<body>整個內容與div和應用overflow: hidden它。

.wrapper { 
    overflow: hidden; 
} 

https://i.imgur.com/gPpaxlH.png以此爲參考。我已經包裹了除腳本和div之外的所有內容,因爲我認爲這是使用JS生成的。從<body>刪除overflow-x

在任何項目中,都要遵循此規則。

+0

非常感謝你@Lucian。它解決了。 –

+0

不客氣:) – Lucian

0

試試這個

* { margin:0; padding:0; } 
 
body { 
 
      background-image: url("http://unsplash.it/2500/1000"); 
 
      -webkit-background-size: cover; 
 
      -moz-background-size: cover; 
 
      -o-background-size: cover; 
 
      background-size: cover; 
 
      background-position:center; 
 
      background-attachment: fixed; 
 
      
 
     }
<body> 
 

 
</body>