2015-04-02 131 views
0

好吧我对这个问题感到有点沮丧。CSS背景仍在重复

平台 - WordPress的

<style type="text/css"> 
body { 
background: url(<?php echo $src[0]; ?>) !important; 
background-width: 100%; 
background-repeat: no-repeat; 
background-attachment: fixed; 
} 
</style> 

我有越来越的背景大小的页面宽度的100%,因此,它会在页面的两侧显示的问题,并得到它固定和停止重复。下面

http://i.stack.imgur.com/XJPOA.png

示例显示了背景,在上面你可以看到,如果我缩小它仍然重复,如果我是那一页,它仍然重复进一步滚动,也图像是不是100%宽度。

包含在background: url(<?php echo $src[0]; ?>) !important;中的PHP可以在下面找到。

<?php 
$src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), array(5600,1000), false, ''); 
?> 
+0

哪里是你的'背景position'规则? – 2015-04-02 03:42:03

+0

@ Mike'Pomax'Kamermans我不完全确定这是否正确,但我相信如果我用CSS上传图像,我可以使用''background-attachment:fixed; ''它具有相同的效果,请纠正我,如果我错了。 – Lee 2015-04-02 03:43:43

+0

'background-attachment:fixed'仅使背景独立于视口,因此滚动页面内容不会滚动背景图像。 – 2015-04-02 03:46:21

回答

0

你试试这个

<style type="text/css"> 
body 
{ 
    background: url(<?php echo $src[0]; ?>) no-repeat center top; 
    background-width: 100%; 
    background-attachment: fixed; 
} 
</style> 
+0

谢谢萨加尔你刚刚解决了我的问题。 – Lee 2015-04-02 03:54:51

0

尝试应用在你的CSS文件,这些CSS,它应该工作

body{ 
     position:relative; 
     float: left; 
     width: 100%; 
     overflow: hidden; 
     background-attachment: fixed; 
     -webkit-background-size: cover; 
     -moz-background-size: cover; 
     -o-background-size: cover; 
     background-size: cover; 
     background-repeat: no-repeat; 
     background-position: center center; 
     background-color: #F6E3CE; 
     // or background-image: url(your image); 


}