我为我的wordpress主题启用了自定义背景,如下所示:
add_theme_support('custom-background', array(
'default-color' => 'FFF',
'default-image' => get_template_directory_uri() . '/img/bg.jpg'
));然后我获取body的类".custom-background“,因为我想更改背景大小:
body.custom-background {
background-attachment: fixed!important;
background-position: center center!important;
background-repeat: no-repeat!important;
background-size: cover!important;
top: 0;
right: 0;
bottom: 0;
left: 0;
position: absolute;
}我将其定位为绝对背景的唯一原因是,我想添加一个具有相同背景属性但宽度为1000px、居中页边距(自动为0)的其他背景,以便使用css-filters模糊此部分:
body.custom-background:before {
content: "";
background-image: url(""); //here he should takes the custom background-image (of body.custom-background)
background-attachment: fixed!important;
background-position: center center!important;
background-repeat: no-repeat!important;
background-size: cover!important;
height: 100%;
right: 0;
left: 0;
margin: 0 auto;
width: 1000px;
position: fixed;
z-index: -1;
filter: blur(10px);
}但是当然wp不知道哪一个是背景图像...那么,我该如何解决这个问题--他再次将自定义的背景图像带到:before选择器?
希望你能理解我的意思。
发布于 2014-12-13 04:35:41
您可以在header.php中编写以下代码
<?php $background = set_url_scheme( get_background_image() ); ?>
<style>
body.custom-background:before {
content: "";
background-image: url("<?php print $background; ?>");
background-attachment: fixed!important;
background-position: center center!important;
background-repeat: no-repeat!important;
background-size: cover!important;
height: 100%;
right: 0;
left: 0;
margin: 0 auto;
width: 1000px;
position: fixed;
z-index: -1;
filter: blur(10px);
}
</style> 这会成功的..。
https://stackoverflow.com/questions/19344862
复制相似问题