Firebug で、body
要素の css が 2 回表示されていることに気付きました (最初にすべてのルールが削除されます)。最初のbody
要素は URL から取得されます。http://localhost:3000/assets/application.css?body=1
2 番目の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 参照が 1 つしかありません。
<!DOCTYPE html>
<html>
<head>
<title>whatever</title>
<%= stylesheet_link_tag "application", :media => "all" %>
最後に、ビューには CSS への参照がまったくありません。