Less-multiple2
提供:Dev Guides
少ない-複数&
説明
- &*は、最も近いセレクターを表すだけでなく、すべての親セレクターも表します。
例
次の例は、LESSファイル内のすべての親セレクターを表す*&*の使用法を示しています-
parent_selector
<html>
<head>
<link rel = "stylesheet" href = "multiple1.css" type = "text/css"/>
</head>
<body>
<div class = "grand_parent">
<h3>Welcome to finddevguides</h3>
<p class = "parent"> It is possible to reference the
parent selector by using &(ampersand) operator.</p>
<p class = "parent_class">It is possible to reference the
parent selector by using &(ampersand) operator.</p>
</div>
</body>
</html>
次に、_style.less_ファイルを作成します。
style.less
.grand_parent {
.parent {
& > & {
color: #A9F5F2;
}
& & {
color: #D0FA58;
}
&& {
color: #81BEF7;
}
&, &_class {
color: #A4A4A4;
}
}
}
次のコマンドを使用して、_style.less_ファイルを_style.css_にコンパイルできます-
lessc style.less style.css
上記のコマンドを実行します。それは次のコードで自動的に_style.css_ファイルを作成します-
style.css
.grand_parent .parent > .grand_parent .parent {
color: #A9F5F2;
}
.grand_parent .parent .grand_parent .parent {
color: #D0FA58;
}
.grand_parent .parent.grand_parent .parent {
color: #81BEF7;
}
.grand_parent .parent,
.grand_parent .parent_class {
color: #A4A4A4;
}
出力
上記のコードがどのように機能するかを確認するには、次の手順に従ってください-
- 上記のHTMLコードを parent_selector ファイルに保存します。
- このHTMLファイルをブラウザで開くと、次の出力が表示されます。