2015-04-02 132 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); 


}