简体   繁体   English

如何保持已编译的LESS中退出的CSS

[英]How do I keep my exiting CSS from compiled LESS

I'm start using LESS in a project today and found a problem, lets describe this - 我今天开始在一个项目中使用LESS,发现一个问题,让我们描述一下-

I always use predefined CSS Reset and as well as WordPress Core CSS along with my upcoming CSS in any project that I work on. 在我从事的任何项目中,我总是使用预定义的CSS Reset和WordPress Core CSS以及即将发布的CSS。 The problem was not happened before I use LESS. 在我使用LESS之前,没有发生此问题。

When I write new LESS code and compiled it through SimpLESS application or any other compiler, I just got my existing CSS (Reset, WP Core) code removed from my stylesheet (.css) and update the stylesheet with new CSS compiled code. 当我编写新的LESS代码并通过SimpLESS应用程序或任何其他编译器进行编译时,我只是从样式表(.css)中删除了现有的CSS(重置,WP Core)代码,并使用新的CSS编译代码更新了样式表。

It's really annoying for me as I'm using LESS for the first time. 当我第一次使用LESS时,这真的让我很烦。

So, how to I keep my exiting CSS and the compiled CSS both at once? 那么,如何同时保留现有的CSS和已编译的CSS?

Thanks in advance! 提前致谢! :) :)

Two options: 两种选择:

  1. Put your existing CSS in your LESS code. 将现有的CSS放入LESS代码中。 Your LESS code will overwrite your css file on every save, so you'll manage all of your styles with LESS. 您的LESS代码将在每次保存时覆盖您的css文件,因此您将使用LESS管理所有样式。

  2. Change the name of your LESS file so you're not overwriting your existing CSS code, then put links to both stylesheets in your HTML document, or by putting this line in your LESS file: 更改LESS文件的名称,以免覆盖现有的CSS代码,然后将指向两个样式表的链接放在HTML文档中,或者将此行放在LESS文件中:

     @import (css) "foo.css"; 

why dont you compile your less to a separate style sheet and include both in your page head? 为什么不将少部分内容编译为单独的样式表,并将两者都包含在页面标题中? The problem is if you are compiling from style.less to style.css without including your existing css code in your less, it will overwrite the file not append to it. 问题是,如果您是从style.less编译为style.css,而没有在less中包含现有的CSS代码,则它将覆盖未附加到该文件的文件。

So either use the solution above and include your existing css in your less, or compile to a different file name and include both css files in your document head. 因此,要么使用上面的解决方案,然后在您的less中添加现有的CSS,要么编译为其他文件名,并将两个CSS文件都包含在文档头中。

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

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