CSS背景仍在重复

时间:2015-04-02 03:38:59

标签: php css wordpress

好吧,我对这个问题感到有点沮丧。

平台 - 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, '' );
?>

2 个答案:

答案 0 :(得分:0)

你试过这个吗?

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

答案 1 :(得分: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);


}