【发布时间】:2016-05-12 12:52:37
【问题描述】:
我有一个 css 文件,它在许多不同的元素上使用一种颜色。我希望能够指定一个全局变量(例如:$color1)来为我设置颜色,而不是使用 jquery 来动态更改每个元素。
下面是一个示例,其中颜色#F54F36 用于许多不同的元素。我目前正在使用 jQuery 来动态更改这些元素,但我想看看是否有办法在 CSS 中定义全局变量。
::selection {
background: #F54F36;
color: #fff;
}::-moz - selection {
background: #F54F36;
color: #fff;
}#jpreBar, .patern span, .red, .nav - button span, .inner - overlay, .skillbar - bar, .serviseslider h3 span, .icon - holder, .subscriptionForm input#submitButton, #loadingProgress, .sepcolor, .quote - icon, .skillbar - bar, #facts ul li h6, #closeProject a, #ajaxpage a.lanch - project, #clientlist, #contact_form textarea: focus,
#contact_form input: focus,
.owl - theme.owl - controls.owl - page.active span,
.owl - theme.owl - controls.clickable.owl - page: hover span,
.slides - pagination a.current,
.slides - pagination a: hover,
.submit_btn: hover,
.resume - head,
.resume - line,
.resume - date,
.download - resume {
background: #F54F36;
}.ajl,
.bigtext,
.sections - head,
.slides - container h1 span,
.error,
#options li: hover,
#options li.actcat,
.social - list ul li a: hover,
.num,
.project - description h3,
.project - details h3,
.subcribe div#error,
.subcribe div#success,
.smallicon: hover,
.footer,
.company - color {
color: #F54F36;
}#team.content,
#options li.back,
#subscribe.content,
#prices.content {
border - top: 2px solid#F54F36;
}#facts ul li h6: before {
border - bottom - color: #F54F36;
}#testimonials.content {
border - top: 2px solid#F54F36;
border - bottom: 2px solid#F54F36;
}.actser: after {
border - top - color: #F54F36;
}.inner a: hover,
.inner li.current a {
color: #F54F36;
border - right: 2px solid#F54F36;
}.customNavigation a.next - slide {
background: #F54F36 url(.. / images / pl - small.png) no - repeat center;
}.customNavigation a.close {
background: #F54F36 url(.. / images / close - white.png) no - repeat center;
}.customNavigation a.btn: hover {
box - shadow: 0 0 0 2px rgba(255, 255, 255, 0.1),
0 0 10px 10px#F54F36,
0 0 0 10px rgba(255, 255, 255, 0.5);
}.triangle {
border - color: transparent#F54F36 transparent transparent;
}.popup - gallery a span {
background: #F54F36 url(.. / images / pl - small.png) no - repeat center;
}.social - list ul li.back {
border - top: 1px solid#F54F36;
}.to - top: after {
border - bottom - color: #F54F36;
}.flex - direction - nav.flex - next {
background: #F54F36 url(.. / images / project - next1.png) no - repeat center;
}.flex - direction - nav.flex - prev {
background: #F54F36 url(.. / images / project - prev1.png) no - repeat center;
}.right - date: before {
border - right - color: #F54F36;
}.left - date: before {
border - left - color: #F54F36;
}.resume - circle {
border: 2px solid#F54F36;
}.resume - slider {
border - bottom: 10px solid#F54F36;
}
【问题讨论】:
-
使用 LESS、SASS 或 Stylus :)
-
这种情况是否存在网站的基本 .css 文件,并且该网站的用户可以选择自定义某些部分,并且每个用户可能有不同的自定义?
-
您是在问如何拥有变量(作为开发人员,在这种情况下,像 SASS 这样的答案最有意义)还是在问您网站的访问者如何设置背景颜色结束了?
-
这里有问题吗?如果您知道自己需要 CSS 预处理器,为什么不阅读它们或尝试一下?
-
@bagofmilk 包含 [sass] 和 [less](都是 CSS 预处理器)标签似乎意味着您非常了解这里需要的内容。既然如此,下一步合乎逻辑的步骤是研究这些技术,看看它们是否能解决您的问题。