hover property in CSS doesn't work when I have an inline styles

前端 未结 2 1772
再見小時候
再見小時候 2021-01-26 06:07

I was work on a HTML document and I wanted to use the hover property for a HTML: div element but it didn\'t work. here the HTML div and the CSS style I used

<         


        
相关标签:
2条回答
  • 2021-01-26 06:41

    Inline styles can be overridden by !important, as they take up more importance.

    div:hover {background-color: red !important;}
    

    Something a bit about the specificity.

    Since you have the style attribute, it overrides all the other things! It is a sin to use !important:

    0 讨论(0)
  • 2021-01-26 06:51

    Inline style have the highest priority. If you need to override in CSS, need to use !important

    div:hover {background-color: red !important;}
    
    0 讨论(0)
提交回复
热议问题