php - 将 CSS 中的背景图像添加到高级自定义字段 (ACF)
问题描述
我有点卡在这个部分。当背景图像位于 html 中时,我只在 html 中添加了 ACF php。现在我的 css 中有 2 个带有伪元素的形状。我将如何添加 php 使其适用于 wordpress?
HTML
<section class="main-content-section home">
<section class="hero-section" style="background-image: url(images/home-hero@2x.jpg);"></section></section>
CSS
.hero-section:before,.home .hero-section:after{position: absolute; left: 0; top: 0; content: ""; background-image: url(../svgs/Rectangle.svg); background-position: left top; background-size: contain; background-repeat: no-repeat; width: 64.25%; height: 100%; z-index: -1;}
.home .hero-section:after{background-image: url(../svgs/Rectangle-Copy.svg); background-position: right bottom; left: auto; top: auto; right: 0; bottom: -46%; width: 63.125%;}
解决方案
最简单的方法可能是<style>
在模板中包含内联标记,使用 ACF 字段中的图像,因为您不能直接在 HTML 中的伪选择器上使用内联样式。
IE:
<style type="text/css">
.home .hero-section:after {
background-image: url('<?= get_field('your_acf_image_field')['url'] ?>');
}
</style>
推荐阅读
- php - 双 foreach 与 html 集体和采摘
- javascript - 在 Node.js 中嵌套承诺的情况下承诺解决/拒绝
- javascript - 随机数列表缺少数字 1
- sql-server - 如何在 SSRS 报告中动态调整图像的高度和宽度?
- python - 如何将列表分成大小相等的块,如果列表是奇数,我想将块添加到前一个块
- regex - RegEx 用于匹配关键字后的一到三个单词
- user-interface - 有没有办法在 Lua 中创建 GUI?
- android - 未找到 Android SDK,即使设置了 ANDROID_HOME 环境变量,在 cmd 中键入 'android' 也能获得完美的结果
- amazon-web-services - 意外的延迟问题 AWS-API Gateway
- docker - 适用于 Windows Server 2016 的 docker dotnet 2.1 和 2.2 映像