Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

css: does every class support :hover state?

Tags:

html

css

If I use a class for a normal div, can I write the css like:

.messagebc:hover {
...
}

Is it legal?

like image 707
Bin Chen Avatar asked Nov 17 '10 12:11

Bin Chen


People also ask

Can you use hover on a class in CSS?

The :hover selector CSS pseudo-class is used to style elements when the mouse hovers over them. It can be used on every element.

Why is my hover CSS not working?

Also, hover will not work if you use the wrong CSS format. Note that if you do not get the specificity right, the hover style will not work.

How do you hover in class?

The :hover selector is used to select elements when you mouse over them. Tip: The :hover selector can be used on all elements, not only on links. Tip: Use the :link selector to style links to unvisited pages, the :visited selector to style links to visited pages, and the :active selector to style the active link.


1 Answers

It's ineffiecient to use :hover on non-link elements.

Avoid the :hover pseudo-selector for non-link elements for IE clients.

If you use :hover on non-anchor elements, test the page in IE7 and IE8 to be sure your page is usable. If you find that :hover is causing performance issues, consider conditionally using a JavaScript onmouseover event handler for IE clients.

:hover pseudo-selector to non-link elements is a very ineffiecient selector (e.g): For example:

h3:hover {...}
.foo:hover {...}
#foo:hover {...}
div.faa :hover {...}

The :hover pseudo-selector on non-anchor elements is known to make IE7 and IE8 slow in some cases*. When a strict doctype is not used, IE7 and IE8 will ignore :hover on any element other than anchors. When a strict doctype is used, :hover on non-anchors may cause performance degradation.

More info on un-effiecient selectors

like image 60
Blowsie Avatar answered Oct 20 '22 21:10

Blowsie