文档级别 [英] Document Level Less

查看:160
本文介绍了文档级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一个学校的项目工作,并想使用较少的图书馆。我尝试过像

< link rel =stylesheet / lesstype =text / csshref =style.less>
但这没有工作,我得到错误
XMLHttpRequest不能加载 file:/// [..] /style.less。只有HTTP支持跨源请求。
含义我基本上需要为这个实现运行一个服务器。但是,由于这应该是一个非技术类的独立项目,运行服务器是不成问题。所以,我的问题是:

I am working on a project for school and wanted to use the less library. I tried something like
<link rel="stylesheet/less" type="text/css" href="style.less"> but this didn't work, I got the error XMLHttpRequest cannot load file:/// [..] /style.less. Cross origin requests are only supported for HTTP. Meaning I basically need to run a server for this implementation. However, since this is supposed to be a stand-alone project for a non-technical class, running a server is out of the question. So, my question is:

如何在文档级别使用更少,就像编写css等效的方式一样

< style> div {color:#F00}< / style>

How do I use less at document level, the same way one would write the css equivalent
<style>div{color:#F00}</style>?

没有返回任何相关结果。

Searching the google for "document level less" returned no related results.

推荐答案

您不能在文档级别使用LESS。 less是CSS的预编译器,因此您应该使用您的网站(css)中的最终产品。您不需要一个网络服务器在webbrowser中显示html + css local。你可以编译你的LESS到CSS客户端(通过包括less.js)或者服务器端,源代码捆绑一个编译器。
另请阅读:有没有办法绕过Javascript / jQuery的本地访问的相同的源策略?

You can't use LESS at document level. Less is a pre compiler for CSS, so you should use the end product in your site (css). You don't need a webserver to show html + css local in a webbrowser. You can compile your LESS to CSS client side (by including less.js) or server side, the source code bundles a compiler. Also read: Is there a way to bypass Javascript / jQuery's same origin policy for local access?

例如下面的文件也工作,当我加载它从我在webbrowser中的本地文件:

for example the file like below works also when i load it from my local files in a webbrowser:

<html>
<head>
    <link rel="stylesheet" media="(max-width: 767px)" href="green.less" />
    <link rel="stylesheet" media="(min-width: 768px)" href="red.less" />
    <script type="text/javascript">less = { env: 'development' };</script>
    <script src="less.js" type="text/javascript"></script>
</head> 
<body>
<p>color this text</p>
</body>
</html>

更新
js加载,你看不到你的样式,他们可能会是一个错误或打字错误在你的LESS文件。如果有错误,你的LESS文件将无法编译,所以他们将是任何CSS,你不会看到任何样式。
默认情况下,less.js不会在浏览器中显示错误。在您的来源中添加< script type =text / javascript> less = {env:'development'};< / script> 您的浏览器(从: http://stackoverflow.com/a/11289000/1596547 )。

update When you are sure javascript works and less.js loads and you don't see your styles still, their probably will be an error or typo in your LESS files. If there is an error, your LESS file won't compile, so their will be any CSS and you won't see any styling. By default less.js don't show errors in the browser. Add <script type="text/javascript">less = { env: 'development' };</script> to your source to allow LESS errors shown in your browser (from: http://stackoverflow.com/a/11289000/1596547).

示例:

这篇关于文档级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆