0

enter image description here enter image description here

This is a reactjs project, Te amperzand syntax is working fine in Javascript file but not in css.

How to write hover class in css file?

1

2 Answers 2

1

If you want to write in same class. You should use Sass/Scss.

Save the css file with .scss extension. It is a precprocessor for better syntax.

Refer this sandbox:

https://stackblitz.com/edit/react-uwktzj?file=src%2FApp.js

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

Comments

1

You must write it this way

.baseStyle {
 /* base styles goes here*/

}

.baseStyle:hover {
/* hover styles goes here */
}

If you wish to attain what you intend you must use scss.

Then it will be like

.class {
    margin:20px;
    &:hover {
        color:yellow;
    }
}

Reference

  1. Using Scss in React

5 Comments

It's not working, also my question is how to write that in same class
You cannot write it using normal css in same place. This is how css works.
Then why it is working in js like this ':hover': { background: '#40a9ff' }
It was working in js fine but not getting how to write the same in css, The formal method you answered is also not working.
You must understand that css and js have different syntax. You simply cannot expect it to work by copy pasting. Please take a look at the reference provided now.

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.