首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在wordpress中再次添加自定义背景图像

在wordpress中再次添加自定义背景图像
EN

Stack Overflow用户
提问于 2013-10-13 19:51:20
回答 1查看 505关注 0票数 1

我为我的wordpress主题启用了自定义背景,如下所示:

代码语言:javascript
复制
add_theme_support('custom-background', array(
    'default-color' => 'FFF',
    'default-image' => get_template_directory_uri() . '/img/bg.jpg'
));

然后我获取body的类".custom-background“,因为我想更改背景大小:

代码语言:javascript
复制
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模糊此部分:

代码语言:javascript
复制
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选择器?

希望你能理解我的意思。

EN

回答 1

Stack Overflow用户

发布于 2014-12-13 04:35:41

您可以在header.php中编写以下代码

代码语言:javascript
复制
<?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>  

这会成功的..。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19344862

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档