I’m creating a special UI control using HTML/CSS to mimic the Windows 7 Control Panel buttons. So far, I’ve got the layout right and now I’d like to add some cosmetics to it.
As seen here, there is a gradient that appears when you hover over the button with your mouse.
http://m.cncfps.com/zack/files/this-control.png
Now, you can see here that I’ve got the layout done. I’d like to add a :hover effect to the whole div item with a background image.
Currently, here is what I have for the CSS- yet it doesn’t work. No image shows up in IE8, or FireFox
EDIT: It works in Chrome, but not in FireFox or IE.
#cp .cp-item:hover
{
background:url(images/hoverbg.png) repeat-x;
}
It does however work with a background-color rather than an image.
It already works in Chrome.
Chrome seems to be more intelligent (or lenient) than other browsers. If I inspect the page, it’s inserting stuff:
It doesn’t work in other browsers because you don’t have a proper page structure (no doctype, no
<html>tag, no<body>tag, etc) – your page doesn’t validate, and the other browsers do not “like it”. I don’t know the exact reason why it doesn’t work with the other browsers – I imagine the reason is either an implementation detail, or buried within the W3 spec.This works in “all browsers”:
Live Demo
(I’m using the
<base>tag to make the paths work)It’s your exact code, wrapped in typical boilerplate, with the addition of the
<base>tag.