少有什么好处?

发布于 2024-12-01 16:52:40 字数 193 浏览 10 评论 0原文

http://lesscss.org/

是的,该语言语法看起来很酷,但是有什么显着的优点吗?

因为从我看来,你实际上编写了更多的 CSS,并且由于 javascript 编译了更少的样式表,所以你会在几秒钟内得到一个未样式化的网站......

http://lesscss.org/

Yeah the language syntax looks cool, but are there any significant advantages?

Because from what I see there you actually write more CSS, and since the less stylesheet gets compiled by javascript you get a un-styled site for a few seconds...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

末骤雨初歇 2024-12-08 16:52:40

也就是说,如果您使用 lesscss 来生成客户端工作表。

您还可以在服务器端使用lesscss,甚至可以预先编译您的工作表。

例如,如果您使用 node.js,您可以在服务器上生成工作表。
此外,如果您愿意,您可以使用它来编写更易于管理的模板,然后“编译”您的工作表以生成成型的样式表,以便您在阅读生产时使用。

我认为这是完全有道理的,因为这意味着当您处于开发阶段时,您可以通过单个十六进制颜色更改来更改颜色集合。当您准备好部署时,您可以预先编译,然后将该样式表与您的项目一起分发。

考虑可管理性并使用命令行编译器。

命令行

http://lesscss.org/

Less 带有一个二进制文件,它允许您从
命令行,如下所示:

$ lessc styles.less

这会将编译后的 CSS 输出到 stdout,然后您可以将其重定向到您选择的文件:

$ lessc styles.less > styles.css

要输出缩小的 CSS,只需传递 -x 选项。

That is if you use lesscss for client side sheet generation.

You can also use lesscss on the server side or even compile your sheets before hand.

For example, if you are using node.js you can generate your sheets on the server.
Additionally, if you want, you can use it as a way to write more manageable templates and then "compile" your sheets to generate a formed style sheet for when you are reading for production.

I think it makes perferct sense, because it means that while you are in development, you can change a collection of colors in a single hex color change. When you are ready to deploy, you can compile before hand and then distribute that style sheet with your project.

Think about manageability and using the command line compiler.

Command Line

http://lesscss.org/

Less comes with a binary, which lets you invoke the compiler from the
command-line, as such:

$ lessc styles.less

This will output the compiled CSS to stdout, you may then redirect it to a file of your choice:

$ lessc styles.less > styles.css

To output minified CSS, simply pass the -x option.

我还不会笑 2024-12-08 16:52:40

为什么要使用 LESS 编写更多 CSS?反之,你就写得少了。而且你编写的代码比普通的 CSS 更加冗长。您可以更好地创建组、使用继承...您只是比使用 CSS 更好地概述样式。

我的项目 CSS 文件目前有超过 800 行...在 LESS 中,只有 150 行左右。

对于 javascript 编译:我通常使用离线编译器并只上传编译后的 CSS,所以我不必与 JS 客户端大惊小怪。

Why would you write more CSS using LESS? In the contrary, you write less. And the code that you write is way more verbose than normal css. You can create groups better, use inheritance... You just have a way better overview over your styling than you do with CSS.

My CSS-file for a project currently has over 800 lines... in LESS, it's just around 150.

And to the javascript-compiling: I generally use an offline compiler and upload just the compiled CSS, so I don't have to fuss with the JS client.

阪姬 2024-12-08 16:52:40

你可以使用预编译器(ruby 有一个很酷的预编译器,可以在 win 下运行)。

尝试用 less 编写一个网站,你将永远不想再回到正常的 css :) 我自己的经验......

You can use a precompiler (ruby's got a cool one, got it running under win).

Try writing a site in less and you'll never want to get back to normal css again :) my own experience...

和影子一齐双人舞 2024-12-08 16:52:40

实际上有一个 LESS PHP 编译器,我一直在使用它。我认为弄清楚为什么它比 CSS 更好的最好方法是自己使用它,但我会总结一些事情:

  • 例如,如果您到处都使用主题颜色,并且想要更改它们,那么这很容易使用 LESS 的变量系统。
  • 实际上,您编写的标记比普通 CSS 少,因为不必重新输入长选择器字符串。
  • 例如,如果您想使用跨浏览器圆角,则 mixins 可以将重复减少到几乎没有;您所要做的就是创建一个包含样式定义的类,然后简单地“混合它”。本质上它是一个可重用的函数。如果您需要更改所有圆角元素的特定内容,只需更改单个函数即可。
  • 是的,语言语法看起来很酷我个人认为这是相当轻蔑和无知的;如果您查看一下 LESS 示例,您会发现它在可用性和开发速度方面比普通 CSS 领先英里

还有更多原因,但这些应该足以让您开始。

There is actually a LESS PHP compiler, which I use all the time. I think the best way to work out why it's better than CSS is to use it yourself, but I'll summarise some things:

  • If you have theme colours used all over the place, for example, and want to change them, it's very easy with LESS's variable system.
  • You actually write less markup than vanilla CSS, due to not having to retype long selector strings.
  • If you want to, say, use cross-browser rounded corners, the mixins reduce repetition to almost nothing; all you do is create a class with style definitions in it, and then simply "mix it in". Essentially it's a re-usable function. If you need to change something specific to all rounded corners elements, you just change the single function.
  • Yeah the language syntax looks cool Personally I think this is rather dismissive and ignorant; if you have a look around the LESS examples, you will see it is miles ahead of normal CSS in terms of usability and speed of development.

There are more reasons, but these should be enough to get you started.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文