Skip to content
Related Articles

Related Articles

Improve Article

Display div element on hovering over <a> tag using CSS

  • Last Updated : 30 Jul, 2021

We can apply CSS to display div element on hover a tag by using an adjacent sibling selector. The Adjacent sibling selector is used to select the element that is adjacent or the element that is the next to the specified selector tag.
This combinator selects only one tag that is just next to the specified tag.

To display div element using CSS on hover a tag:

  • First, set the div element invisible i.e display:none;.
  • Second, By using the adjacent sibling selector and hover on a tag to display the div element.

Example: This Example illustrates how to display the div element on hovering a tag.




<html>
  
<head>
    <style>
        h1 {
            color: green;
        }
          
        div {
            display: none;
        }
          
        a:hover + div {
            display: block;
            color: green;
            font-size: 25px;
        }
    </style>
</head>
  
<body style="text:align:center;">
    <h1>GeeksforGeeks</h1>
    <b>
      Hovering below element to see 
      the <div> element.
  </b>
    <br>
    <br>
    <a>GeeksforGeeks</a>
    <div>
      A computer science portal for Geeks.
  </div>
</body>
  
</html>

Output:
Before Hovering On the tag:

After Hovering On the tag:

CSS is the foundation of webpages, is used for webpage development by styling websites and web apps.You can learn CSS from the ground up by following this CSS Tutorial and CSS Examples.




My Personal Notes arrow_drop_up
Recommended Articles
Page :