0

I am creating an application, created multiple CSS files but those are not able to import.

I tried by installing css-loader and style-loader. But it doesn't help

Please look below picture, I have Burger.css file. but it not visible to import

enter image description here

3
  • Does your import classess from './Layout.css' works ? Because I don't think you can do that. Usually you will import a css file as follow : import './Layout.css' and it will be applied to you code. Commented Sep 26, 2020 at 9:22
  • No, it is also not working @QuentinGrisel Commented Sep 26, 2020 at 9:25
  • What happens if you actually type out the full name, ../Burger/BurgerIngredient/Burger.css? Is there an error message? Commented Sep 27, 2020 at 17:04

3 Answers 3

1

VS Code by default doesn't autocomplete all file types. If you write import ./Burger/Burger.css or import ./Burger/BurgerIngredient/BurgerIngredient.css in your Layout.js file, your css files will be loaded fine.

If you want to use autocomplete for all files in VS Code, you can use this extension.

https://marketplace.visualstudio.com/items?itemName=ionutvmi.path-autocomplete

Without Extension

Without Extension

With Extension

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

0

Ok since you confirmed that your ./Layout.css import does not work, you should not name your import when it's about a css file. Doing :

import './myFile.css';

is enough to apply your css.

Note that css is global in React, so you might want to use styled component or encapsulate your css to prevent side effect on other components).

Now, if you really want to add style the way you tried to, there is the style attribute which accepts an object. So you could do:

<div style={{backgroundColor: 'red'}}>Hello World !</div>

Note that the css properties are written in camelCase.

1 Comment

I think he is trying to use CSS modules here in his css import. css-tricks.com/css-modules-part-1-need
0

Your file structure appears to me to be...

-Burger
--BurgerIngredient
----Burger.css
--Layout
----Layout.css

Your primary application, from what it appears here, is in /Burger. Considering that, when you type import, you see the dropdown appear, showing helpful suggestions, and it lists...

-../Burger/BurgerIngredient/...

As a possible, valid location. In that case, why don't we try importing css, by typing out...

import burgercss from '../Burger/BurgerIngredient/Burger.css';

Note, for instance, Burger.css wouldn't show up until you select BurgerIngredient, because that's its conntaining folder.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.