简体   繁体   English

如何在CSS中使用Less变量

[英]How to use Less variables in CSS

Ok, so I am not new to using Bootstrap, but I am new to customizing it and using the LESS variables. 好的,所以我对使用Bootstrap并不陌生,但是对它进行自定义并使用LESS变量并不陌生。 I am trying to do the simplest of things just to check to see if the LESS variables are even working. 我正在尝试做最简单的事情,只是检查一下LESS变量是否还在工作。

I am trying to set the body's background-color to @brand-success just to test it. 我正在尝试将主体的背景色设置为@ brand-success,以进行测试。 It is not working. 它不起作用。 Chrome tells me that it is an invalid property value. Chrome告诉我这是无效的属性值。

I know that I've used LESS variables from Bootstrap in jQuery before, but I thought that the CSS file worked in the same way. 我知道我以前在jQuery中使用过Bootstrap中的LESS变量,但是我认为CSS文件以相同的方式工作。

I'm not sure if it makes any difference but I am using the bootstrap.css file locally instead of linking it from an external sever like I do the jQuery files. 我不确定是否有什么区别,但是我在本地使用bootstrap.css文件,而不是像使用jQuery文件那样从外部服务器链接它。

I don't know if this is a duplicate question or not. 我不知道这是否是重复的问题。 I tried my best to search for the answer but the questions were all seemingly different than mine. 我尽力寻找答案,但问题似乎都与我的不同。

Less is a CSS pre-processor . Less是CSS 预处理器 You can use pure CSS in Less, so CSS is less, but the opposite is not true. 您可以在较少使用纯CSS,CSS所以少了,但相反的是不正确的。 Chrome has no idea what Less is. Chrome不知道什么是Less。 It only interprets CSS. 它仅解释CSS。 @brand-sucess is not valid CSS. @brand-sucess无效的CSS。

It may have worked in PHP because probably your PHP application previously ran a less pre-processor before sending the CSS file to the client. 它可以在PHP中工作过,因为很可能你的PHP应用程序发送的CSS文件给客户前在过去跑了较少的预处理器。

It may have worked in JQuery if you are using a client-side Less pre-processor. 如果您使用客户端的Less预处理器,它可能已经在JQuery中起作用。 In this case, you can send LESS directly to the client, but first it must be transformed into a real CSS color (ex: #58fe23) before Chrome can do anything with it. 在这种情况下,您可以将LESS直接发送给客户端,但是首先必须将其转换为真实的CSS颜色(例如:#58fe23),然后Chrome才能对其进行任何处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM