How to display an element on hover with CSS?

CSSWeb DevelopmentFront End Technology

To display an element on hover with CSS, the code is as follows −

Example

 Live Demo

<!DOCTYPE html>
<html>
<head>
<style>
   body{
      margin:20px;
      padding:20px;
      font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
   }
   .hiddenText {
      display: none;
   }
   .hoverDiv:hover + .hiddenText {
      display: block;
      color: rgb(71, 0, 65);
      font-size: 22px;
      font-weight: bold;
   }
</style>
</head>
<body>
<h1>Display an Element on Hover Example</h1>
<div class="hoverDiv" style="font-size: 18px;">Hover over me.</div>
<div class="hiddenText">This text is shown by hovering on the above div</div>
</body>
</html>

Output

The above code produces the following output −

On hovering over the “Hover over me” text −

raja
Published on 07-May-2020 11:09:49
Advertisements