我在 Firebug 中注意到body
元素的 css 显示了两次(第一次所有规则都被删除)。第一个body
元素来自 url:http://localhost:3000/assets/application.css?body=1
第二个body
元素来自 url:
http://localhost:3000/assets/scaffolds.css?body=1
我在名为 header.css.scss 的目录中添加了另一个 scss 文件/app/assets/stylesheets
。/assets/header.css
就像我想要的那样,它现在被包含在所有网页中。但是 application.css 再次在每个页面中复制其所有内容。
我做错什么了吗?我不应该在资产中创建 header.css.scss 文件吗?为什么我的所有 css 规则都被复制了?
更新:我的 application.css 文件中只有一些简单的 css:
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the top of the
* compiled file, but it's generally better to create a new file per style scope.
*
*= require_self
*= require_tree .
*/
body {
margin: 0;
}
#content {
padding: 10px;
background-color: #eee;
}
code {
background-color: #d0d0d0;
padding: 1px 3px;
}
我的 header.scss 文件与 application.css 没有任何共同之处:
@import "compass/css3/images";
header {
border-bottom: 1px solid #6787d2;
height: 7em;
position: relative;
background-color: #f0edee;
background-image: url("/assets/background_header.png");
padding: 10px 10px 0 10px;
box-shadow: 0 -1px 3px #C0BABB inset;
}
header address {
background-color: #b9dd8c;
@include filter-gradient(#b9dd8c, #5ab86d, vertical);
$experimental-support-for-svg: true;
@include background-image(linear-gradient(top, #b9dd8c 0%,#5ab86d 100%));
border: 1px solid #15905b;
}
application.html.erb
布局只有一个 CSS 参考:
<!DOCTYPE html>
<html>
<head>
<title>whatever</title>
<%= stylesheet_link_tag "application", :media => "all" %>
最后,视图没有任何对 CSS 的引用。