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('/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.
| Attachment | Size |
|---|---|
| video-play.zip | 6.63 KB |
Comments
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
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.
hi, this css trick very
hi, this css trick very usefull for web 2.0 :D
thanks a lot for sharing
Хороший у вас блог! удачи в
Хороший у вас блог! удачи в развитии
Thank you so much dude!!! You
Thank you so much dude!!! You just made a web rockstar of me in my office...
this is an amazing tutorial
this is an amazing tutorial very well described as well.
Hey, I came to your site from
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 worked for me
This worked for me
Do you have some idea how you
Do you have some idea how you can show a mouse over text using CSS?
Hello, You can apply a
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,
Thanks
Thanks
Add new comment