【问题标题】:how to link background image in stylesheet Wordpress?如何在样式表 Wordpress 中链接背景图像?
【发布时间】:2017-01-19 19:53:33
【问题描述】:
.jumbotron {
    margin-bottom: 0px;
    background-image: url(../img/desktop-urania.jpg);
    min-height: 600px;
    background-attachment: fixed;
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
}

这是 HTML 中的工作 CSS,但我正在尝试将 HTML 转换为 WordPress,同时转换我在 function.php 中链接我的样式表 (函数 urania_script_enqueue() { wp_enqueue_style('customstyle', get_template_directory_uri() . '/css/urania.css', array('$handle', '$src', '$deps', '$ver', '$media'), '1.0. 0', '全部');)

但是图片没有加载...

主题名称 URANIA:: -> Css-> urania.css(样式表) 主题名称 URANIA:: -> img -> desktop-urania.jpg (image)

请帮忙

【问题讨论】:

  • CSS 文件加载正确,但图片加载不正确?
  • 图像未打印...
  • .jumbotron { margin-bottom: 0px;背景图片:url(../img/desktop-urania.jpg);我也试过了,但仍然没有打印图像..
  • jumbotron 正在打印但如何添加背景图片?
  • 没什么好说的,有什么办法可以提供链接吗?您是否尝试过检查控制台是否有错误?

标签: php html css wordpress


【解决方案1】:

PHP 不能在 css 文件中工作,但您可以使用内联的 wordpress 函数。你可以只使用css。由于我的 css(在 sass 处理之后)最终在主题根目录中的一个文件中,我不得不更改我的文件路径。

以下 stackoverflow 答案解决了我的问题。 CSS background images in WordPress

尝试仔细检查您的文件路径或遵循 wp 约定并将 css 放在根目录中的 styles.css 中。见get_template_directory_uri()。也可能 wordpress 喜欢引号中的路径?

.jumbotron {background-image: url("images/desktop-urania.jpg")}

【讨论】:

    【解决方案2】:

    请检查您的图像颜色模式,如果您的图像颜色模式是 CMYK,那么它不会在 IE-8 上显示,您需要将颜色模式更改为 RGB。

    如果你的图片颜色模式是正确的,那么如果你能分享实际的站点 URL 就更好了,这样我们就可以正确地看到站点的结构了。

    【讨论】:

      猜你喜欢
      • 2017-10-02
      • 2011-08-07
      • 2021-07-15
      • 2018-09-20
      • 2011-06-17
      • 1970-01-01
      • 1970-01-01
      • 2011-05-26
      • 1970-01-01
      相关资源
      最近更新 更多