css - 将 PureCSS 添加到 MVC 4.5 包

标签 css asp.net-mvc yui-pure-css

我目前正在学习 MVC 风格的 ASP.NET 4.5,我决定完全删除 Bootstrap 并使用 PureCSS ( http://www.purecss.io )。

这主要是因为我的 Web 应用程序几乎不需要脚本,除了代码隐藏和一些用于数据验证等的轻型 JS。

目前我正在链接到来自 Yahoo! 的组合 PureCSS 样式表。内容分发网络:

<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.6.0/pure-min.css">

在我的 _Layout.cshtml 文件中。这显然是实用的,但是我有两个问题:

  1. 如果 CVN(无论出于何种原因)失败/关闭/更改,所有样式都会消失,我将不得不即时解决该问题(或实现一段时间的故障安全切换到另一个 CDN)
  2. 我真的很喜欢捆绑的概念,我想捆绑本地 PureCSS 库,以防止上述问题以及模块化/分区化。

生成这个包是一件简单的事情:

bundles.Add(new StyleBundle("~/Content/css").Include(
                    "~/Content/purecss_release_1_6/some.css",
                    "~/Content/purecss_release_1_6/other.css",
                    "~/Content/purecss_release_1_6/neat.css",
                    "~/Content/purecss_release_1_6/etc.css",
                    ...
                    "~/Content/site.css"));

如果是这样,那就很好了,但是发行版中有 DOZENS 个 css 文件。有没有更简洁的方法来捆绑它们?

谢谢!

最佳答案

您可以使用 IncludeDirectory引用包含所有 CSS 文件的整个目录。

针对您的情况的示例:

bundles.Add(new StyleBundle("~/Content/css")
    .IncludeDirectory("~/Content/purcss_release", "*.css"));

.NET 4.5 中的新功能是一个集成系统,用于从失败的 CDN 回退到本地资料。教程/资料:http://www.hanselman.com/blog/CDNsFailButYourScriptsDontHaveToFallbackFromCDNToLocalJQuery.aspx

来自上面链接的可用信息:

The basic idea for CDN fallback is to check for a type or variable that should be present after a script load, and if it's not there, try getting that script locally. Note the important escape characters within the document.write. Here's jQuery:

<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-2.0.0.min.js"></script>
<script>
if (typeof jQuery == 'undefined') {
    document.write(unescape("%3Cscript src='/js/jquery-2.0.0.min.js' type='text/javascript'%3E%3C/script%3E"));
}
</script>

关于css - 将 PureCSS 添加到 MVC 4.5 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31522011/

相关文章:

yui-pure-css - Purecss 网格偏移类

html - 为什么我在 html 表单上的输入字段的样式与 PureCSS 网站的样式不同?

jquery - 使图像适合液体父级

html - 高分辨率 CSS Sprite

css - 自定义字体不会在 Firefox for Rails 4 应用程序中呈现

c# - 添加dom后表达注释重新绑定(bind)表单

javascript - 相互使用 Razor 和 javascript

css - 添加到 parsys 的内容显示在包含 html 之外。我怎样才能让它显示在里面?

css - 使用 MVC3 时设置固定页面高度

css - Yahoo Pure CSS 中的媒体查询