gpt4 book ai didi

css - 使用 title 和 rel 属性组合和最小化 css

转载 作者:行者123 更新时间:2023-11-28 11:17:59 25 4
gpt4 key购买 nike

我一直在阅读有关 css 和 js 压缩和最小化的内容。特别是那个帖子Concatenate and minify JavaScript on the fly OR at build time - ASP.NET MVC我正在开发 MVC ASP.NET 应用程序并使用 Combres 最小化和压缩文件。我不太高兴,现在我正在按照 Scott 在提到的帖子中的建议评估 MVCScriptManager。

但是我的 css 文件有问题:在我的站点中,我允许用户更改页面的样式,我完成了定义不同样式表的任务。

要在用户单击按钮时更改样式,我使用链接标记的“title”属性启用正确的样式:

$('link[rel*=style][title]').each(function(i) {
this.disabled = true;
if (this.getAttribute('title') == styleName) this.disabled = false;
});

在我页面的头部部分,我拥有的是:

<link rel="stylesheet" type="text/css" href="/Content/css/green.css" title="Green" media="screen" />    
<link rel="alternate stylesheet" type="text/css" href="/Content/css/cyan.css" title="Cyan" media="screen" />
<link rel="alternate stylesheet" type="text/css" href="/Content/css/orange.css" title="Orange" media="screen" />
<link rel="alternate stylesheet" type="text/css" href="/Content/css/navy.css" title="Navy" media="screen" />
<link rel="alternate stylesheet" type="text/css" href="/Content/css/purple.css" title="Purple" media="screen" />
<link rel="alternate stylesheet" type="text/css" href="/Content/css/pink.css" title="Pink" media="screen" />
<link rel="alternate stylesheet" type="text/css" href="/Content/css/wine.css" title="Wine" media="screen" />

问题是,当我组合样式表时,我不能依赖 title 和 rel 属性来进行切换。任何帮助或建议将不胜感激!

提前致谢!

最佳答案

好吧,您真的应该按需加载 CSS 文件。

因此,如果用户选择粉红色,pink.css <link>将作为 <head> 中的最后一个元素插入.

关于css - 使用 title 和 rel 属性组合和最小化 css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3018976/

25 4 0
文章推荐: css - 自动包装一个具有动态宽度的
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com