2017-02-27 90 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>