0

I import my css file like:

import styles from "./Documentation.module.css";

Use the style here:

<button
    className={styles.button}
    onClick={(e) => selectDoc(m.id)}
    >
    <b>{m.title}</b>
</button>

The css for the button looks like:

.button {
    color: "#d0e6a5";
    background-color: "#5d684b";
    border: "none";
    border-left: "4px solid #d0e6a5";
    font-size: "28px";
    padding: "6px 12px";
    margin: "3px";
    width: "200px";
}

but the css doesnt get applied to the button element. This happens to all styles. I have no more idea what the proplem could be.

Using inlined or "style" is no option for me here, sice the css will get a bunch more. Any idea how i could diagnose the problem here?

14
  • You need bundlers like webpack or rollup to make CSS imports work. Do you use them? Commented Dec 20, 2022 at 7:36
  • You need to have [email protected] and higher to use this feature i.e CSS Modules Stylesheet Commented Dec 20, 2022 at 7:41
  • @VladislavKibenko i run my app with npm start in debug. in release, i build it. tbh i dont know since my knownledge is limited still. Commented Dec 20, 2022 at 7:44
  • @BilalNasir package.json tells me i use react-scripts `6.3.0 Commented Dec 20, 2022 at 7:45
  • Could you console.log(styles) to make sure, webpack correctly imports this CSS? In case, it is not, check if you typed correct imported file name Commented Dec 20, 2022 at 7:47

1 Answer 1

1

The bug is in the css file the syntax is incorrect. You dont have to put quotes in he values. Try to replace it with the following css

.button {
color: #d0e6a5;
background-color: #5d684b;
border: none;
border-left: 4px solid #d0e6a5;
font-size: 28px;
padding: 6px 12px;
margin: 3px;
width: 200px;}
Sign up to request clarification or add additional context in comments.

3 Comments

your point is correct. but it doesnt fix my problem. but i indeed now did fix my css.
in the end it was indeed the faulty css.. credits to you. my mistake why i didnt spot it right away, i removed the .module from the css filename.
also big credit to @Vladislav Kibenko he helped out a lot by deagnosing the proplem.

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.