0

这是“.rb”文件:

class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception

def bg
  @images  = ["bg1.jpg", "bg2.jpg", "bg3.jpg", "bg4.jpg", "bg5.jpg","bg6.jpg","bg7.jpg","bg8.jpg"]
  @random_no = rand(8)
  @random_image = @images[@random_no]
end

end

这是“css.scss”文件:

#welcome
{
  background-image:url();
}

我想要background-image显示@random_image,但我不知道应该是什么url()

谢谢!

4

1 回答 1

2

简而言之,您不能通过 .css 动态更改背景,因为它加载一次,但您可以在布局文件中指定样式。查看类似的问题

于 2013-10-29T05:22:22.080 回答