JSRUN 用代码说话

!important keyword

编辑教程

!important keyword

!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 。

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

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

lessc style.less style.css

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

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

输出

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

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

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

Welcome to Tutorialspoint
LESS is a CSS pre-processor that enables customizable, manageable and reusable style sheet for web site.
LESS is a CSS pre-processor that enables customizable, manageable and reusable style sheet for web site.
JSRUN闪电教程系统是国内最先开创的教程维护系统, 所有工程师都可以参与共同维护的闪电教程,让知识的积累变得统一完整、自成体系。 大家可以一起参与进共编,让零散的知识点帮助更多的人。
X
支付宝
9.99
无法付款,请点击这里
金额: 0
备注:
转账时请填写正确的金额和备注信息,到账由人工处理,可能需要较长时间
如有疑问请联系QQ:565830900
正在生成二维码, 此过程可能需要15秒钟