【问题标题】:adding background image in style rails 4在样式 Rails 4 中添加背景图像
【发布时间】:2015-06-15 14:30:55
【问题描述】:

我正在尝试在我的网页上添加背景图片,当我使用平面 html 时它可以工作,但现在我正在将它集成到我的 rails 应用程序中。

我正在使用此代码将图像嵌入到我的 rails 应用程序中

  <div class="jumbotron" style="background-image:                                                                                                                                                            
                                    "url(image-url('lines3.png')";                                                                                                                                             
                                      background-repeat: repeat-x;                                                                                                                                             
                                      background-position: center bottom">

它没有在日志中抛出任何异常,但也没有显示图像,可以建议

【问题讨论】:

  • 在 chrome 检查器中查看 div 的呈现 html。查看实际的图像 url 是什么,并检查您是否可以在另一个选项卡中将该 url 作为独立 url 访问。这应该会指出问题所在。

标签: ruby-on-rails twitter-bootstrap ruby-on-rails-4 asset-pipeline


【解决方案1】:

你应该把"background-image:"url(image-url('lines3.png')";改成"background-image:"image-url(image-url('lines3.png')";

http://guides.rubyonrails.org/asset_pipeline.html#css-and-sass


或者你可以试试:background-image: url(&lt;%= asset_path 'lines3.png' %&gt;)

【讨论】:

  • 你的意思是删除 div 和 style 标签
  • 不,我的意思是将url() 更改为image-url()。也许这会有所帮助。
  • 它们都不起作用,我想问题是它在 div 和 style 中
  • 你的图片是否放在app/assets/images目录下?
  • 你不应该使用内联样式。 @pavan 答案应该适合你。
【解决方案2】:

你可以这样做

<div class="jumbotron">
</div>

CSS

<style>

.jumbotron{
  background-image: image-url('lines3.png');
  background-repeat: repeat-x;
  background-position: center bottom;
  }

</style>

【讨论】:

    猜你喜欢
    • 2015-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-28
    • 2014-02-03
    • 1970-01-01
    • 2011-02-25
    • 2018-06-26
    相关资源
    最近更新 更多