You are hereBlogs / alif's blog / Show Play Icon on Mouse over Thumbnail using CSS

Show Play Icon on Mouse over Thumbnail using CSS


By alif - Posted on 18 January 2010

I decided to share a simple trick on how to display a "Play" image when mouse is hovered over a video Thumbnail using only CSS. (Sites like Metacafe and similar ones have this feature). Its very easy to implement.

At first, lets declare a simple CSS class for a thumbnail inside an anchor Tag.

.item { width: 125px; height: 80px; }	
.item a { text-decoration: none; display:block; }
.item a img { border: solid 1px #ccc; padding: 1px;}	

Note: I added a wrapper 'item' class for convenience.

The above CSS class is self-explanatory. I will add an img tag inside an "anchor" tag. To display a play icon/image on hover, I will add another "span" tag inside the "anchor" tag. The "span" tag will have a height equals to the height of Thumbnail, a negative top-margin, a z-index. I give it a class name "play". The CSS code is below:

.item { width: 125px; height: 80px; }	
.item a { text-decoration: none; display:block; }
.item a img { border: solid 1px #ccc; padding: 1px;}	

// the span item for showing play icon. 
.item a span.play { display:none; background: url('http://www.itsalif.info/blogfiles/video-play/play-arrow.png') center center no-repeat; margin: -80px 10px 0 0; height: 80px; position: relative; z-index: 100; opacity: 0.8; filter: alpha(opacity=80); }
.item a:hover span.play { display:block; }

Though I used a span, however, any other allowable tag can be used.

Now I add the following Code:




The Result is below:

As can be seen, a nice "play" icon is displayed when mouse is hovered over the image. The method works fine on IE7/8, FF 2/3, Safari and Google Chrome. Unfortunately, this doesn't work on IE-6 using CSS, hence a work-around using Javascript is needed.

AttachmentSize
video-play.zip6.63 KB
Tags

Thanks

Do you have some idea how you can show a mouse over text using CSS?

Hello,

You can apply a similar technique on the text. Perhaps wrap the text with a tag and then apply :hover onto that tag.

I would be able to assist you better if you can provide a bit more details.

Regards,

This worked for me

Hey,

I came to your site from stackoverflow. http://stackoverflow.com/questions/6417543/show-play-icon-on-link-mouseover

Thanks a bunch for sharing this useful snippet.

Regards,
John

this is an amazing tutorial very well described as well.

Thank you so much dude!!! You just made a web rockstar of me in my office...

Хороший у вас блог! удачи в развитии

hi, this css trick very usefull for web 2.0 :D

thanks a lot for sharing

This page was indexed by Google and added to blogs search 18 Feb 2009 17:11:43 GMT.

Webroot informers.

This is a very smart idea to show hover image icon with combination of z-index and display, opacity is also cool.
I was hoping a video will play which I clicked the image :p
Anyway, nice article. Keep 'em coming :-)

- Hossain

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.