CSS 无法让 less.js 工作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6372211/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 00:47:12  来源:igfitidea点击:

Can't get less.js to work

cssless

提问by Knarf

I can't get less.js to work and I have no idea why. Heres the HTML i tried:

我不能让 less.js 工作,我不知道为什么。这是我尝试过的 HTML:

<!DOCTYPE HTML>
<html lang="en">
    <head>
        <meta charset="utf-8" />

        <!-- CSS -->
        <link rel="stylesheet/less"  href="main.less" />

        <!-- Javascript -->
        <!-- <script src="http://lesscss.googlecode.com/files/less-1.0.18.min.js"></script> -->
        <script src="less-1.0.18.min.js" type="text/javascript"></script>

    </head>
    <body>
        <p>
            Lorum ipsum
        </p>
    </body>
</html>

And heres main.less:

这里是 main.less:

p {
    color: blue;
}

The less-1.0.18.min.js file is downloaded from http://lesscss.googlecode.com/files/less-1.0.18.min.js. All files is in the same folder. I have no idea why this isn't working...

less-1.0.18.min.js 文件是从http://lesscss.googlecode.com/files/less-1.0.18.min.js下载的。所有文件都在同一个文件夹中。我不知道为什么这不起作用......

Tested in Chrome 12.0.742.100

在 Chrome 12.0.742.100 中测试

Edit

编辑

Tried the lates less.js file (less-1.1.3.min.js). That one did also not work.

尝试了后期的 less.js 文件(less-1.1.3.min.js)。那一个也没有用。

Okay now...

好了现在...

This works:

这有效:

<link rel="stylesheet" type="text/less" href="main.less" />

But only as normal css, no less specific markup.

但只是作为普通的 css,没有更少的特定标记。

This doesn't work at all:

这根本不起作用:

<link rel="stylesheet/less" type="text/less" href="main.less" />

Also, this isn't working:

此外,这不起作用:

<link rel="stylesheet/less" type="text/css" href="main.less" />

What the hell? How do I get less to work?

我勒个去?我如何减少工作时间?

Found the error

发现错误

P.S.S. Less.js browser script currently won't work if you're using Chrome and the path to your page starts with “file:///” due to a known Chrome issue.

如果您使用 Chrome,并且由于已知的 Chrome 问题,您的页面路径以“file:///”开头,则 PSS Less.js 浏览器脚本当前将无法工作。

Soruce

采纳答案by Vennsoh

P.S.S. Less.js browser script currently won't work if you're using Chrome and the path to your page starts with “file:///” due to a known Chrome issue.

如果您使用 Chrome,并且由于已知的 Chrome 问题,您的页面路径以“file:///”开头,则 PSS Less.js 浏览器脚本当前将无法工作。

But what we could do is setting up a local testing environment using wamp (pc) or mamap (mac). It will work alright then.

但是我们可以做的是使用 wamp (pc) 或 mamap (mac) 设置本地测试环境。它会正常工作。

回答by verglor

You can use the command-line switch -allow-file-access-from-fileswhen starting chrome - it will permit less.js to access local less files.

您可以在启动 chrome 时使用命令行开关-allow-file-access-from-files- 它会允许 less.js 访问本地的 less 文件。

回答by Jason

Even though this was posted a while ago I thought I would add a little something for other people stuck on this.

尽管这是前一段时间发布的,但我想我会为其他坚持此问题的人添加一些东西。

If you use a windows machine, you might want to give WinLess a try. Its a pre-compiler for windows. Seems straight forward to use. Good luck. http://winless.org/

如果您使用 Windows 机器,您可能想尝试一下 WinLess。它是 Windows 的预编译器。使用起来似乎很直接。祝你好运。 http://winless.org/

回答by heisenberg

Need to add

需要添加

type="text/css"

类型=“文本/CSS”

to your css link.

到您的 css 链接。