Languages
[Edit]
EN

CSS - show text on hover

3 points
Created by:
Saim-Mccullough
718

In this article, we would like to show you how to show text on hover using CSS.

Simple steps:

  1. create two elements: div.container and div.text (inside div.container),
  2. set div.text element as invisible by default using display: none property,
  3. add :hover pseudo-class for div.container element defining display: block property on div.text.

Practical example:

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<head>
  <style>

    body {
        height: 50px;
    }

    div.container {
        padding: 5px;
        border-radius: 5px;
        background: #28a745;
        width: 70px;
        height: 15px;
        color: white;
    }

    .text {
        padding: 5px;
        position: relative;
        left: 75px;
        top: 5px;
        background: #bebebe;
        width: 100px;
        height: 15px;
        color: black;
        display: none;   /* <----- hides text by default */
    }

    div.container:hover .text {
        display: block;  /* <----- shows text on hover   */
    }

  </style>
</head>
<body>
  <div class="container">
    Hover me!
    <div class="text">Example text...</div>
  </div>
</body>
</html>

 

See also

  1. JavaScript - show text on hover

References

  1. :hover - CSS: Cascading Style Sheets | MDN
  2. Pseudo-classes - CSS: Cascading Style Sheets | MDN

Alternative titles

  1. CSS - show text on parent element hover
  2. CSS - reveal text on parent element hover
  3. CSS - text show up on parent element hover
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join