Less-importing
提供:Dev Guides
LESS-インポート
説明
LESSまたはCSSファイルの内容をインポートするために使用されます。
例
次の例は、LESSファイルでのインポートの使用方法を示しています-
<html>
<head>
<title>Less Importing</title>
<link rel = "stylesheet" type = "text/css" href = "style.css"/>
</head>
<body>
<h1>Example using Importing</h1>
<p class = "myclass">LESS enables customizable,
manageable and reusable style sheet for web site.</p>
<p class = "myclass1">It allows reusing CSS code and
writing LESS code with same semantics.</p>
<p class = "myclass2">LESS supports creating cleaner,
cross-browser friendly CSS faster and easier.</p>
</body>
</html>
_myfile.less_ファイルを作成します。
myfile.less
.myclass {
color: #FF8000;
}
.myclass1 {
color: #5882FA;
}
ここで、_style.less_ファイルを作成します。
style.less
@import "http://www.finddevguides.com/less/myfile.less";
.myclass2 {
color: #FF0000;
}
パスリンクから_style.less_にインポートされる_myfile.less_ファイル:/less/myfile.less [https://www.finddevguides.com/less/myfile.less]
次のコマンドを使用して、_style.less_ファイルを_style.css_にコンパイルできます-
lessc style.less style.css
上記のコマンドを実行します。それは次のコードで自動的に_style.css_ファイルを作成します-
style.css
.myclass {
color: #FF8000;
}
.myclass1 {
color: #5882FA;
}
.myclass2 {
color: #FF0000;
}
出力
上記のコードがどのように機能するかを確認するには、次の手順に従ってください-
- 上記のHTMLコードを importingl ファイルに保存します。
- このHTMLファイルをブラウザで開くと、次の出力が表示されます。