【发布时间】:2017-12-16 11:47:57
【问题描述】:
所以我一直在向我的主页添加背景图片,但是,背景图片永远不会加载。
application.scss 文件:
#background {
position: fixed;
top: 50%;
left: 50%;
min-width: 100%;
max-width: 100%;
width: auto;
height: auto;
z-index: -100;
-webkit-transform: translateX(-50%) translateY(-50%);
transform: translateX(-50%) translateY(-50%);
background: url(background.jpg);
background-size: cover;
}
现在,添加同一行背景: url(background.jpg);到身体,会工作:
body {
color: #fff;
text-align: center;
text-shadow: 0 .05rem .1rem rgba(0,0,0,.5);
background: url(background.jpg);
}
所以这行得通,但是当我将背景图像添加到#background 标记时它没有?为什么呢?这是 application.html.erb 文件,我在其中调用#background id:
<!DOCTYPE html>
<html>
<head>
<title><%= @page_title %></title>
<%= csrf_meta_tags %>
<!-- Load in the stylesheet file 'application.scss' -->
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<!-- Load in the javascript file 'application.js' -->
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
<body>
<div class="site-wrapper">
<div class="site-wrapper-inner">
<div class="cover-container">
<div id="background"></div>
<!-- Alerts for devise -->
<p class="notice"><%= notice %></p>
<p class="alert"><%= alert%></p>
<!-- Render the nav bar from the shared folder -->
<%= render "shared/application_nav"%>
<!-- Yield content -->
<%= yield %>
<!-- Render footer from the shared folder -->
<%= render "shared/footer"%>
<!-- Load in Gemfile for the Copyright Logo -->
<%= source_helper %>
</div>
</div>
</div>
</body>
</html>
将标签更改为底部并没有改变任何东西。使用 background-image、image-url、url('background.jpg') 的变体;相反也没有帮助。
-webkit-transform 等都是从#background id 工作的。
有什么想法会导致这种情况吗?
提前致谢!
【问题讨论】:
-
谢谢!我已经尝试过了,但图像仍然没有出现,即使我改变了 div 的高度/宽度(我之前做过),图像仍然不可见。这是一些错误,因为将 id/class 的名称更改为其他名称最终解决了问题。
标签: html css ruby-on-rails ruby-on-rails-5