我在Firebug中注意到body
元素的css顯示兩次(第一次觸發所有規則)。第一body
元素來自於網址:http://localhost:3000/assets/application.css?body=1
從Rails中的scss文件複製css
第二屆body
元素來自於網址: http://localhost:3000/assets/scaffolds.css?body=1
我又增加了SCSS文件中/app/assets/stylesheets
目錄下名爲header.css.scss。現在,所有的網頁都包含/assets/header.css
,就像我想要的那樣。但application.css再次複製了每個頁面中的所有內容。
我做錯了什麼?我不應該在資產中創建header.css.scss文件嗎?爲什麼我所有的CSS規則都被重複了?
UPDATE:我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。
什麼是你application.css.scss文件的頂部?另外,你是否包括HTML中的application.css?你只應該有一個CSS鏈接到application.css。 –
隨着資產管道的開發,您可以分別獲得所有文件,'application.css'不應包含其餘文件中的任何代碼。你應該在你的文件系統中發佈整個'application.css'(而不是提供給瀏覽器的那個)。 – rewritten