html - Reveal text on hover -
i trying hide <h2>
element until user hovers on image.
so when user moves cursor on image, reveal word 'drinks' on image. i'd text centered on image too.
can show me how achieve in css?
demo: https://jsfiddle.net/hj3xrumo/
li { list-style-type: none; padding: 0; margin: 0 } li h2 { position: relative; top: 0; }
<h1> test </h1> <li class="product-category product first"> <a href="#"> <img src="http://placehold.it/370x370" alt="drinks" width="370" height="370" /> <h2 class="woocommerce-loop-category__title">drinks</h2> </a> </li>
use position: absolute;display:none;
h2
, make display: block
on img:hove
ul { padding: 0; margin: 0; } li { list-style-type: none; padding: 0; margin: 0; position: relative; display:inline-block; } li h2 { position: absolute; top: 50%; left: 50%; transform: translate(-50%); display: none; margin:0; } li a:hover h2 { display: block }
<ul> <li class="product-category product first"> <a href="#"> <img src="http://placehold.it/370x370" alt="drinks" width="370" height="370" /> <h2 class="woocommerce-loop-category__title">drinks</h2> </a> </li> </ul>
Comments
Post a Comment