gpt4 book ai didi

c# - 如何从代码隐藏更改我的 css 文件中使用的颜色?

转载 作者:行者123 更新时间:2023-11-30 12:25:34 25 4
gpt4 key购买 nike

我的许多 css 文件(包括 Bootstrap )都使用指定的颜色。我希望能够在一个中心位置更改主要颜色(例如我正在添加的配置页面)。

我已经看到 css var 可能很快就会出现,但目前还没有得到很好的支持。

有没有比我目前使用 css 文件作为模板的更优雅的方式,我将在页面加载时使用颜色配置加载模板?

最佳答案

你可以使用 LESS代替 CSS 具有变量和更多优势。

如果将 LESS 与分离到不同 CSS 文件的主题结合使用(如@Thorarins 所建议的那样),您将变得更加强大和可维护。

较少的功能:

1) 变量

LESS

@link-color: #CC0000;

a {
color: @link-color;
}

“编译”为

CSS

a {
color: #CC0000;
}

2)嵌套

LESS

.article {
a {
text-decoration: underline;
}

p {
margin: .5ex .5em;
}
}

“编译”为

CSS

.article a {
text-decoration: underline;
}

.article p {
margin: .5ex .5em;
}

3) 混合

LESS

.box-shadow(@style, @color)
{
-webkit-box-shadow: @style @color;
box-shadow: @style @color;
}

div
{
.box-shadow(0 0 5px, 30%);
}

“编译”为

CSS

div {
-webkit-box-shadow: 0 0 5px 30%;
box-shadow: 0 0 5px 30%;
}

4) 函数

LESS

@text-color: #000;

.article {
p {
color: lighten(@text-color);
}
}

“编译”为

CSS

.article p {
color: #4d4d4d;
}

关于c# - 如何从代码隐藏更改我的 css 文件中使用的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31263570/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com