Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tailwind CSS: display text on image hover

How can I show text on image hover, using Tailwind CSS: display text on image hover?

Here is my image? I want text "mammals" to be displayed when user hovers image?

<img src="/img/cat/categories/mammals.png" alt="mammals" class="max-w-full max-h-full">
like image 513
renathy Avatar asked Jan 27 '21 10:01

renathy


3 Answers

I prefer to play around with position relative and absolute because it gives me more options to work with. Check out this code Display text on hover

<div class="w-64 h-64 bg-red-100 relative">
  <div class="absolute inset-0 bg-cover bg-center z-0" style="background-image: url('https://upload.wikimedia.org/wikipedia/en/3/3c/JumanjiTheNextLevelTeaserPoster.jpg')"></div>
  <div class="opacity-0 hover:opacity-100 duration-300 absolute inset-0 z-10 flex justify-center items-center text-6xl text-white font-semibold">Dwayne</div>
</div>
like image 172
Digvijay Avatar answered Nov 15 '22 16:11

Digvijay


You can use the title atribute in your img tag.

<img src="/img/cat/categories/mammals.png" alt="mammals" class="max-w-full max-h-full" title="mammals">
like image 9
luxa_code Avatar answered Nov 15 '22 15:11

luxa_code


Please use this code works well

  <div class="relative ">
    <a class="absolute inset-0 z-10 bg-white text-center flex flex-col items-center justify-center opacity-0 hover:opacity-100 bg-opacity-90 duration-300">
      <h1  class=tracking-wider >Title</h1>
      <p  class="mx-auto">Description</p>
      </a>
    <a href="#" class="relative">
        <div class="h-48 flex flex-wrap content-center">
            <img src="/image_url" class="mx-auto  " alt="">
        </div>
    </a>
  </div>

enter image description here

like image 6
ExpertWeblancer Avatar answered Nov 15 '22 17:11

ExpertWeblancer