Show Play Icon on Mouse over Thumbnail using CSS

Tags:

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

This page was indexed by

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

Webroot informers.

Very smart!

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

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

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.
2 + 17 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.