Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CSS背景图像未显示CSS HAML_Css_Ruby On Rails 4_Background Image_Haml - Fatal编程技术网

CSS背景图像未显示CSS HAML

CSS背景图像未显示CSS HAML,css,ruby-on-rails-4,background-image,haml,Css,Ruby On Rails 4,Background Image,Haml,我在样式表中有一个背景图像url,我正试图为索引页面中的标题呈现该url。图像位于“资源/图像”文件夹中。我尝试输入供应商/资产/图像,但也无法从那里进行渲染 views/splash/index.html.haml: %section.row.header-bg .row .col-md-6.col-md-offset-1 资产/样式表/splash.css.scss: .header-bg{ background-image: url('bg.png'); } 编辑:

我在样式表中有一个背景图像url,我正试图为索引页面中的标题呈现该url。图像位于“资源/图像”文件夹中。我尝试输入供应商/资产/图像,但也无法从那里进行渲染

views/splash/index.html.haml:

%section.row.header-bg
  .row
    .col-md-6.col-md-offset-1
资产/样式表/splash.css.scss:

.header-bg{
    background-image: url('bg.png');
}

编辑:我尝试了我能想到的图像URL的所有变体,但到目前为止运气不佳。

尝试这样做:希望这能帮助你

background-image: url('images/bg.png');

or
background-image: url('assets/images/bg.png');

看起来您正在将css文件夹作为图像的目标。 假设您的图像和样式表文件夹位于供应商/资产文件夹中,您将需要向上导航一级

尝试在url前面加上/

background-image: url('../images/bg.png');

请像这样尝试它会起作用:


背景图片:图片url('bg.png')

问题解决了。正确的CSS:

.header-bg{
  background: image-url('bg.png') no-repeat;
}

尝试使用开发工具检查呈现的HTML中的元素。您可以查看规则是否正在应用,是否被某个内容覆盖,或者图像是否无法被覆盖found@redbmk我得到一个404未找到错误。url正在查看图像/bg.png是否尝试将图像更改为使用绝对路径?e、 背景图片:url('/assets/images/bg.png')那没用。Inspect元素显示它呈现文本/hml类型。这是什么意思@user3462905我认为您只是将css属性background image更改为background,这不是您的问题,您的主要问题是图像路径不正确;或背景图像:url('/assets/images/bg.png');我仍然得到ActionController::RoutingError(没有与[get]“/assets/images/bg.png”匹配的路由)