SVG图像不显示在Rails中的CSS文件

时间:2015-09-07 11:47:38

标签: css ruby-on-rails svg

我在assets / images目录中有一个名为dot-matrix.svg的图像,该图像没有显示在我的页面上。

我在CSS代码中有一个块

.dotmatrix {
background: url('<% asset_path 'dot-matrix.svg' %>') 50% 0% repeat-y #fff;
height: 100%;
background-size: 50%;
width: 10%;
position: absolute;

}

在视图中我有这个:

<section id="content-receipt" class="clearfix">
   <div id="receipt-container">
   <div class="dotmatrix left"></div>
...
<div class="dotmatrix right"></div>
</div>
<div id="receipt-shadow"></div>

有关为何没有显示的任何想法?注意:我尝试将CS​​S代码从CSS中的asset_path更改为image_path,并将dot-matrix.svg更改为images\dot-matrix.svg - 两者都没有成功。

1 个答案:

答案 0 :(得分:0)

它不起作用,因为你在单引号中放入单引号:

background: url('<% asset_path 'dot-matrix.svg' %>') 50% 0% repeat-y #fff;

您可以通过使用double:

交换其中一组单引号来修复它
 background: url("<% asset_path 'dot-matrix.svg' %>") 50% 0% repeat-y #fff;