Less-guard-logical-operators
提供:Dev Guides
LESS-論理演算子の保護
説明
_and_キーワードを使用して、ガード付きの論理演算子を回避できます。 _and_キーワードを使用してガード条件を組み合わせ、_not_キーワードを使用して条件を無効にすることができます。
例
次の例は、LESSファイルでのガード論理演算子の使用を示しています-
<!doctype html>
<head>
<title>Guard Logical Operators</title>
<link rel = "stylesheet" href = "style.css" type = "text/css"/>
</head>
<body>
<h2>Example of Guard Logical Operators</h2>
<p class = "class1">Hello World...</p>
<p class = "class2">Welcome to finddevguides...</p>
</body>
</html>
次に、_style.less_ファイルを作成します。
style.less
.mixin (@a) when (@a > 50%) and (@a > 5px) {
font-size: 14px;
}
.mixin (@a) when not (@a < 50%) and not (@a < 5px) {
font-size: 20px;
}
.mixin (@a) {
color: @a;
}
.class1 { .mixin(#FF0000) }
.class2 { .mixin(#555) }
次のコマンドを使用して、_style.less_を_style.css_にコンパイルできます-
lessc style.less style.css
上記のコマンドを実行します。それは次のコードで自動的に_style.css_ファイルを作成します-
style.css
.class1 {
font-size: 20px;
color: #FF0000;
}
.class2 {
font-size: 20px;
color: #555;
}
出力
上記のコードがどのように機能するかを確認するには、次の手順に従ってください-
- 上記のHTMLコードを guard_logical_operatorsl ファイルに保存します。
- このHTMLファイルをブラウザで開くと、次の出力が表示されます。