Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using both :after and :hover

Is it possible to only display the :after pseudo using :hover? For example using alternative elements.

#parent{}
#child{display:none;}
#parent:hover >#child{display:block;}

As far as I've got with the same method:

#parent{}
#parent:after{content:'hi';display:none;}
#parent:hover  #parent:after{display:block;}

Is it possible at all? Or am I fooling myself?

like image 377
bashleigh Avatar asked Mar 21 '13 16:03

bashleigh


People also ask

How do you use hover and after together?

The :before and :after selectors in CSS is used to add content before and after an element. The :hover is pseudo-class and :before & :after are pseudo-elements. In CSS, pseudo-elements are written after pseudo-class. In CSS3 double colon(::) is used to denote pseudo-element.

Can we use hover with Div?

To display div element using CSS on hover a tag: First, set the div element invisible i.e display:none;. By using the adjacent sibling selector and hover on a tag to display the div element.

What is a pseudo-element selector?

A CSS pseudo-element is a keyword added to a selector that lets you style a specific part of the selected element(s). For example, ::first-line can be used to change the font of the first line of a paragraph.

What is difference between pseudo class and pseudo-element?

Pseudo-classes enable you to target an element when it's in a particular state, as if you had added a class for that state to the DOM. Pseudo-elements act as if you had added a whole new element to the DOM, and enable you to style that.


2 Answers

You can combine the two:

#parent:hover:after {
    content:'hi';
}

JSFiddle.

like image 190
James Donnelly Avatar answered Sep 22 '22 07:09

James Donnelly


Yes. Not sure why you didn't try it yourself but it's possible:

#parent:hover:after{content:'hi';}

http://jsfiddle.net/uz3w4/

like image 42
Darren Avatar answered Sep 21 '22 07:09

Darren