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が二重に読み込まれてしまっている状態の解決

Last updated at Posted at 2020-05-10

下記のようにcssが重複している状態の際の、解決方法をメモ。

e2cab61830641e9aafa39d226f39ef29.png

原因はapplication.scssの記述によるもの。

/*
 * This is a manifest file that'll be compiled into application.css, which will include all the files
 * listed below.
 *
 * Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's
 * vendor/assets/stylesheets directory can be referenced here using a relative path.
 *
 * You're free to add application-wide styles to this file and they'll appear at the bottom of the
 * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
 * files in this directory. Styles in this file should be added after the last require_* statement.
 * It is generally better to create a new file per style scope.
 *
 *= require_tree .
 *= require_self
 */
 @import "reset";
 @import "scaffolds";
 @import  "items";

Railsにおいて、CSSファイルが読み込まれている理由は、
application.cssファイルに *= require_tree .というコードが、コメントアウトで
記述されているためである。

そのため、SCSSを記載する際に@importを記載すると二重になってしまっていた。
そのため、

 @import "reset";
 @import "scaffolds";
 @import  "items";

この必要なscssの記載のみにすることで回避できました。

上記の違いについては、下記記事が参考になります。

▼requireと@importのそれぞれの仕組みの違い
https://qiita.com/okamoto_ryo/items/1ceaf4ebca2ae3c256bc

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?