简体   繁体   English

在没有localhost /服务器,客户端,浏览器的情况下使用Less

[英]use Less without localhost / server, client-side, browser

I'm trying to work with bootstrap for the first time and so far it works ok. 我正在尝试第一次使用引导程序,到目前为止,它可以正常工作。

However i'm at the media queries that require Less. 但是我在需要较少的媒体查询。 http://getbootstrap.com/css/#grid-media-queries http://getbootstrap.com/css/#grid-media-queries

Right now i have this in the header: 现在我在标题中有这个:

<link rel="stylesheet" type="text/css" href="css/custom.less">
<script type="text/javascript" src="js/less-1.7.4.min.js"></script>

And this is the less file: 这是较少的文件:

/* Small devices (tablets, 768px and up) */
@media (min-width: @screen-sm-min) { 
    background-color: red;
}

/* Medium devices (desktops, 992px and up) */
@media (min-width: @screen-md-min) { 
    background-color: green;
}

/* Large devices (large desktops, 1200px and up) */
@media (min-width: @screen-lg-min) { 
    background-color: blue;
}

I get the following error: 我收到以下错误:

Resource interpreted as Stylesheet but transferred with MIME type text/plain: "file:///Users/doekewartena/Downloads/bootstrap-3.2.0-dist/css/custom.less".

Which is related to this: LESS css variable not working 与此相关: LESS CSS变量不起作用

What i'm wondering. 我在想什么。 Does less needs to run on a server / localhost, and if so why? 不需要在服务器/本地主机上运行吗?如果是,为什么呢?

I use the chrome browser. 我使用Chrome浏览器。

It can run on the client-side/browser as it is written in pure JavaScript (using less.js). 它可以用纯JavaScript编写(使用less.js)在客户端/浏览器上运行。 Read the Getting started tutorial about client-side usage. 阅读有关客户端使用的入门教程

Copy and paste code from that page as writing it yourself is hazardous. 从该页面复制并粘贴代码,因为您自己编写它是危险的。

Common mistakes are: 常见的错误是:

  • The link rel must be rel="stylesheet/less" and NOT rel="stylesheet" ! 链接rel必须为rel="stylesheet/less"不是 rel="stylesheet"
  • Respect the load order as the less JavaScript requires the .less stylesheets files to be loaded before it runs in order to process them ! 遵守加载顺序,因为较少的JavaScript需要在运行之前加载.less样式表文件才能处理它们!
  • Of course make sure the file paths are correct... 当然,请确保文件路径正确...

I recommend to test with the simplest scenario possible (one variable, one less file). 我建议使用最简单的方案(一个变量,一个少文件)进行测试。

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

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