【问题标题】:Inline CSS for dynamic background in RoR app not workingRoR 应用程序中动态背景的内联 CSS 不起作用
【发布时间】:2016-06-29 01:42:42
【问题描述】:

这适用于我的 CSS 文件:

.blog-title-section {
background: image-url('banner-bg.jpg') no-repeat center center;
}

但是我想在我的 html.erb 文件中使背景动态化,到目前为止我已经尝试过

<style>
.blog-title-section { background: image-url('banner-bg.jpg') no-repeat     center center; }
</style>

<div class="blog-title-section", stlye="background: image-url('banner-bg.jpg') no-repeat center center;" >

这两个都不起作用。当我找到有用的东西时,我会将“banner-bg.jpg”替换为@blog.image。

【问题讨论】:

  • 我认为你没有得到图像
  • image-url 是一个 rails-sass 助手,并且您的模板没有被编译...所以,使用 url() 并传递一个完整的 url。 background: url(&lt;%= image_url('banner-bg.jpg') %&gt;)

标签: html css ruby-on-rails


【解决方案1】:

我认为你的图片路径有问题,比如你的图片有app/asset/images/banner-bg.jpg

然后您的代码将image-url('assets/banner-bg.jpg') OR image-url('/assets/banner-bg.jpg') OR image-url('../assets/banner-bg.jpg') 您需要

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-11
    • 2013-06-26
    • 1970-01-01
    相关资源
    最近更新 更多