目录

inline

描述 (Description)

@import (inline)语句将CSS复制到输出CSS文件中而不进行处理。 当CSS文件不兼容时,这很有用。 尽管LESS支持大多数标准CSS,但某些地方不支持注释,如果不修改CSS,它将不支持所有已知的CSS黑客攻击。 即使@import (inline)不会处理CSS,它也会确保所有CSS都在一个文件中。 这是在1.5.0版本中发布的。

例子 (Example)

以下示例演示了在LESS文件中使用reference关键字 -

<html>
   <head>
      <link rel = "stylesheet" href = "style.css" type = "text/css" />
      <title>Import Option Inline</title>
   </head>
   <body>
      <h1>Welcome to IoWiki</h1>
      <p>LESS is a CSS pre-processor that enables customizable, 
      manageable and reusable style sheet for web site.</p>
   </body>
</html>

接下来,创建style.less文件。

style.less

@import (inline) "http://www.iowiki.com/less/import_inline.css";
p {
   color:red;
}

以下代码将使用以下代码从路径https://www.iowiki.com/less/import_inline.cssimport_inline.css文件导入import_inline.css文件 -

import_inline.css

.style {
   font-family: "Comic Sans MS";
   font-size: 20px;
}

您可以使用以下命令将style.less编译为style.css -

lessc style.less style.css

执行上面的命令; 它将使用以下代码自动创建style.css文件 -

style.css

.style {
   font-family: "Comic Sans MS";
   font-size: 20px;
}
p {
   color: red;
}

输出 (Output)

请按照以下步骤查看上述代码的工作原理 -

  • 将上述html代码保存在import_options_inline.html文件中。

  • 在浏览器中打开此HTML文件,将显示以下输出。

内联导入选项少

如果您尝试在.stylep标记内使用.style类,则会抛出undefined error

↑回到顶部↑
WIKI教程 @2018