2013-03-02 54 views
4

我在Rails 3.2应用程序中使用我的样式表进行了以下设置。我有一个application.css文件,其中定义了许多样式,还有其他几个更具体样式的文件,例如与页脚有关的所有文件都在footer.css未针对Rails资产编译CSS样式

在开发中,一切正常,但在生产中,所需文件中的移动样式均未编译,即每个样式表的@media only screen and (min-width: 768px)行以上的所有内容。

主application.css文件有大约700行定义的样式,之后它也有一个@media only screen and (min-width: 768px)媒体查询。在媒体查询中,另外700行覆盖了以前的700行样式,适用于台式机。但是,这些样式已成功编译。我不明白为什么所需的文件不能以相同的方式工作。

application.css

*= require_self 
*= require base.css 
*= require footer.css 

.benefit { 
    display: block; 
    font-size: 0.8em; 
    margin: 1em; 
} 

@media only screen and (min-width: 768px) { 
    .benefit { 
    font-size: 1em; 
    margin: 3em; 
    } 
} 

# All above styles compile 

Base.css

header, section, footer, 
aside, nav, article, figure { 
    display: block; 
} 

html, body { 
    height: 100%; 
    background: #DEDEDE; 
} 

# Above styles don't compile 

@media only screen and (min-width: 768px) { 

# Below style does compile 

    body { 
     text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.2); 
    } 

} 

footer.css

footer { 
    background: #ffffff; 
    width: 100%; 
} 

# Above style doesn't compile 

@media only screen and (min-width: 768px) { 

# Below style does compile 

    footer { 
     background: none repeat scroll 0 0 #000; 
     color: #818A8A; 
     padding: 0; 
    } 
} 

编辑:我试图在this answer和下面的代码更新中建议在他们自己的媒体查询中明确添加所需的css文件的移动样式,但它不起作用。

footer.css

@media only screen { 
    footer { 
    background: #ffffff; 
    width: 100%; 
    } 
} 

# Above style STILL doesn't compile 

@media only screen and (min-width: 768px) { 

# Below style does compile 

    footer { 
     background: none repeat scroll 0 0 #000; 
     color: #818A8A; 
     padding: 0; 
    } 
} 
+0

你seing在资产编译过程中的任何错误?你是手动运行它还是你有Rails配置为自动编译?如果是后者,请尝试运行'rake assets:precompile --trace'并在出现错误时粘贴结果。 – 2013-03-02 19:06:56

+0

当推向Heroku时,Rails会这样做。本地rake任务没有错误,并且在推送到Heroku时输出方面没有任何异常。 – railsuser400 2013-03-02 19:11:15

回答

2

拥有超过1000线的造型,你一定会省略分号或大括号沿线某处。如注释中d_ethier所示,测试的一种方法是使用--trace标志进行编译,但如果资产是纯CSS文件,则编译将无提示失败。

你想要做的是在你的Gemfile中包含sass-rails并将你的样式表重命名为scss文件,这样如果有任何错误,它们将导致编译失败并突出显示你的问题。暂时从application.css文件移到您的样式到另一个文件(假设all.css.scss),以及:

application.css

*= require_self 
*= require all.css.scss 
*= require base.css.scss 
*= require footer.css.scss