Less-mixin-important
提供:Dev Guides
LESS-!importantキーワード
説明
- !important *キーワードは、特定のプロパティをオーバーライドするために使用されます。 mixin呼び出しの後に配置されると、継承されたすべてのプロパティを_!important_としてマークします。
次の例は、LESSファイルでの_!important keyword_の使用を示しています-
<html>
<head>
<link rel = "stylesheet" href = "style.css" type = "text/css"/>
<title>The !important keyword</title>
</head>
<body>
<h1>Welcome to finddevguides</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_importantl ファイルに保存します。
- このHTMLファイルをブラウザで開くと、次の出力が表示されます。