我已经从我正在编写的教程的书中复制了原始文本文件,但是css没有被应用,我不知道为什么。不过,HTML内容可以正确显示。也许你需要我提供更多信息,但我目前不知道,但如果需要的话,我很乐意把它带到谈判桌上。
application.html.erb
<!DOCTYPE html>
<html>
<head>
<title>Depot</title>
<%= stylesheet_link_tag "application", media: "all",
"data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>
</head>
<!-- START_HIGHLIGHT -->
<body class='<%= controller.controller_name %>'>
<!-- END_HIGHLIGHT -->
<%= yield %>
</body>
</html>products.css.scss
// Place all the styles related to the Products controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
/* START_HIGHLIGHT */
.products {
table {
border-collapse: collapse;
}
table tr td {
padding: 5px;
vertical-align: top;
}
.list_image {
width: 60px;
height: 70px;
}
.list_description {
width: 60%;
dl {
margin: 0;
}
dt {
color: #244;
font-weight: bold;
font-size: larger;
}
dd {
margin: 0;
}
}
.list_actions {
font-size: x-small;
text-align: right;
padding-left: 1em;
}
.list_line_even {
background: #e0f8f8;
}
.list_line_odd {
background: #f8b0f8;
}
}
/* END_HIGHLIGHT */发布于 2014-07-10 16:37:48
错误
你修好了--恭喜!
您可能希望考虑使用SASS而不是SCSS。你只需要把文件的扩展名改为.css.sass --这样你就可以去掉SCSS中很多多余的括号了:
#app/assets/stylesheets/application.css.sass
.products
table
border:
collapse: collapse
& tr td
padding: 5px
vertical:
align: top--
样式表
为什么不为每个controller,创建适用的样式表并从中设计body的样式,而不是内联样式化body标记呢?
如下所示:
#app/views/layouts/application.html.erb
<%= stylesheet_link_tag "application", controller_name, media: "all","data-turbolinks-track" => true %>这将允许您在application.css.scss中保留默认样式,并在各种[controller].css.scss文件中使用background image之类的东西:
app
| - assets
| - stylesheets
- application.css.scss
- controller1.css.scss
- controller2.css.scss然后,您需要记住将这些资产添加到pre-compilation procedure中
Rails.application.config.assets.precompile += ['controller1.css', 'controller2.css']这将使您的样式更多DRY和更多用途
https://stackoverflow.com/questions/24666687
复制相似问题