1

I don't know why my input element doesn't change color when hovering

<input
                    id='running'
                    className={filterButtonsSytles.button} 
                    style={{backgroundColor: this.state.running  ? 'grey':'white'}} 
                    type="button"
                    value="Bieganie"
                    onClick={(e)=>this.clickHandler(e)}
                />

css

.button {
    border: 1px solid black;
    cursor: pointer;
}

.button:hover {
    background-color: grey;
}
4
  • What is the output of {filterButtonsSytles.button} ? Commented Feb 15, 2020 at 21:50
  • unless it is .button the above class won't apply Commented Feb 15, 2020 at 21:51
  • I import import filterButtonsSytles from './filterButtons.module.css'; and in the filterButtons.css have this .button. Hover works when i delete "style={{backgroundColor: this.state.running ? 'grey':'white'}} " Commented Feb 15, 2020 at 21:53
  • But i need "style={{backgroundColor: this.state.running ? 'grey':'white'}} " because this.state.running = true means that this button is active, and false that it isn't Commented Feb 15, 2020 at 22:01

1 Answer 1

1

You have to give !important flag on hover because your style in in react element is inline style and inline style does not let override by any external css

To make this right

.button:hover {
background-color: grey!important;
}

To make it more precise !important is not recommended . you should be using classes for this.

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

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.