gpt4 book ai didi

css - 根据 body ID 声明 less 变量

转载 作者:太空宇宙 更新时间:2023-11-04 08:30:54 26 4
gpt4 key购买 nike

我想根据 body id 为变量设置不同的颜色

<body id="theme1">

#theme1{
@brand-color:red;
}
#theme2{
@brand-color:green;
}

h1{color:@brand-color}

最佳答案

你没有使用 Less variables 作为 CSS 属性,而是作为。你需要做的是定义两个不同的变量,分别关联你想要的两种颜色,然后根据主题ID调用相关的变量:

<body id="theme1">
<body id="theme2">

@brand-color-1: red;
@brand-color-2: green;

#theme1 {
color: @brand-color-1;
}
#theme2 {
color: @brand-color-2;
}

这将编译为以下内容(用 <div> 代替 <body>):

#theme1 {
color: red;
}
#theme2 {
color: green;
}
<div id="theme1">
Theme 1
</div>
<div id="theme2">
Theme 2
</div>

希望对您有所帮助! :)

关于css - 根据 body ID 声明 less 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44793608/

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