html – How do I write: hover inside style = ''?

Question:

  • There is no way to connect styles
  • There is no way to insert styles between <style> </style>

<div style="background: #333; padding: 10px;">Dark gray</div>

How to give it a "hover", for example background: #555; right inside style="" ?

Answer:

Pseudo-class selectors cannot be declared directly in a tag. Since there is no way to connect styles, use the onmouseover and onmouseout .

<div style="background: #333; padding: 10px;"
   onmouseover="this.style.backgroundColor='#555';" onmouseout="this.style.backgroundColor='#333';">
      Dark gray
</div>
Scroll to Top