Less-import-options-reference-extend
提供:Dev Guides
LESS-インポートオプションの拡張
説明
セレクターが拡張されると、参照 @ import ステートメントの場所に新しいセレクターが取り込まれ、新しいセレクターのみが_notreferenced_としてマークされます。 extend を使用してこの冗長性を回避し、特定のターゲットスタイルのみを取り込むことができます。
例
次の例は、LESSファイルで_extend_メソッドの使用を示しています-
<html>
<head>
<link rel = "stylesheet" href = "style.css" type = "text/css"/>
<title>Import Options Extend</title>
</head>
<body>
<h1>Welcome to finddevguides</h1>
<p class = "para_1">LESS is a CSS pre-processor that enables customizable, manageable and reusable style sheet for web site.</p>
<p class = "para_2">LESS is a CSS pre-processor that enables customizable, manageable and reusable style sheet for web site.</p>
</body>
</html>
ここで、_style.less_ファイルを作成します。
style.less
@import (reference) "http://www.finddevguides.com/less/import_options_extend.less";
.para_1 {
&:extend(.style1);
background-color: #81F7F3;
}
.para_2 {
&:extend(.style1);
background-color: #F6E3CE;
}
次のコードは、_import_options_extend.less_ファイルをリンクから_style.less_にインポートします。/less/import_options_extend.less[https://www.finddevguides.com/less/import_options_extend.less]パス-
import_options_extend.less
.style1 {
color: #A0A0A0;
font-family: "Comic Sans MS";
font-size: 20px;
}
次のコマンドを使用して、_style.less_を_style.css_にコンパイルできます-
lessc style.less style.css
上記のコマンドを実行します。それは次のコードで自動的に_style.css_ファイルを作成します-
style.css
.para_1,
.para_2 {
color: #A0A0A0;
font-family: "Comic Sans MS";
font-size: 20px;
}
.para_1 {
background-color: #81F7F3;
}
.para_2 {
background-color: #F6E3CE;
}
出力
上記のコードがどのように機能するかを確認するには、次の手順に従ってください-
- 上記のHTMLコードを import_options_reference_extendl ファイルに保存します。
- このHTMLファイルをブラウザで開くと、次の出力が表示されます。