:hover - HTML CSS CSS Selector

HTML CSS examples for CSS Selector:hover

Description

The :hover selector selects elements with mouse over.

:hover must come after :link and :visited if they are present.

Example

Select a <p>, <h1> and <a> element when you mouse over it:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
p:hover, h1:hover, a:hover {
    background-color: red;
}
</style><!--from   ww w  .  ja  va  2 s  . c o  m-->
</head>
<body>

<h1>Welcome to My Homepage</h1>

<div class="intro">
  <h2 id="myId">this is a test</h2>
  <p id="myElement">this is a paragraph</p>
  <p>I <b>like</b> css</p>

    <h2>Links:</h2>
    <p>Here are my favorite websites:</p>
    <a href="https://www.java2s.com">java2s.com</a>
    <a href="http://www.google.com" target="_blank">google.com</a>
    <a href="http://www.wikipedia.org" target="_top">wikipedia.org</a>

</div>


</body>
</html>

Related Tutorials