0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【CSS】外部ファイル読み込みで@importを使う方法

Posted at

プログラミング勉強日記

2021年3月15日

@importとは

 外部のCSSファイルを読み込むときに使う。CSSファイルが1つだと記述量が多くなってしまうので、ファイルを分割するときに使われる。

@importの使い方
/* 同じ階層にファイルがあるとき */
@import url("cssファイル名");

/* 違う階層にファイルがあるとき */
@import url("cssファイルが入ってるフォルダ名/cssファイル名");

サンプルプログラム

 最初にheader.cssbody.cssファイルを作る。
 次に、main.cssを作成してheader.cssbody.css@importで読み込む。

main.css
@import url("./header.css");
@import url("./body.css");
HTMLファイル
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Sample</title>
    // main.cssの読み込み
    <link rel="stylesheet" href="./main.css" />
  </head>
  <body>
  </body>
</html>

参考文献

@import
外部ファイルを読み込む!CSSで@importを使う方法【初心者向け】

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?