LESS !important keyword

2018-01-10 09:36 更新

描述

!important 关键字用于覆盖特定属性。 当它在mixin调用之后放置时,它会将所有继承的属性标记为!important 。


以下示例演示如何在LESS文件中使用!important关键字

<html>
<head>
  <link rel="stylesheet" href="style.css" type="text/css" />
  <title>The !important keyword</title>
</head>
<body>
<h1>Welcome to Tutorialspoint</h1>
<p class="para1">LESS is a CSS pre-processor that enables customizable, manageable and reusable style sheet for web site.</p>
<p class="para2">LESS is a CSS pre-processor that enables customizable, manageable and reusable style sheet for web site.</p>
</body>
</html>

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


style.less

.mixin(){
  color: #900;
  background: #F7BE81;
}
.para1{
  .mixin();
}
.para2{
  .mixin() !important;
}


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

lessc style.less style.css


接下来执行上面的命令,它将用下面的代码自动创建 style.css 文件:

style.css

.para1 {
  color: #900;
  background: #F7BE81;
}
.para2 {
  color: #900 !important;
  background: #F7BE81 !important;
}


输出

让我们执行以下步骤,看看上面的代码如何工作:

  • 将以上html代码保存在 less_mixin_important.html 文件中。

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

输出

以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号