Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change :before when :hover over main DIV?

Tags:

html

css

I have a div that looks like a speech bubble. The main div is the bubble and the :before is the arrow. What I want to do, is when you rollover :hover the DIV in CSS, it will also change the :before.

Here's my code:

.sidebar_image_box_newsfeed_user_info_comments { 
    color: #ffffff; 
    background-color: #2f2f2e;
    text-decoration: none; 
    -webkit-transition-property: background-color, color, text-decoration; 
    -webkit-transition-duration: 0.5s, 0.5s, 0.5s; 
}

.sidebar_image_box_newsfeed_user_info_comments:hover { 
    background-color: #3b3b3b; 
    color: #f3f3f3; 
    text-decoration: underline; 
}

.sidebar_image_box_newsfeed_user_info_comments:before { 
    content:""; position:absolute;
    bottom:-6px; right:0;
    border-width:0 0 6px 6px;
    border-style:solid;
    border-color:transparent #2f2f2e;
    text-decoration: none;
    -webkit-transition-property: background-color, color, text-decoration;
    -webkit-transition-duration: 0.5s, 0.5s, 0.5s;
}
like image 287
iosfreak Avatar asked May 04 '11 02:05

iosfreak


People also ask

How do you make text appear when hovering over a div?

In order to position the text in over the <div>, you need to assign position: relative to the parent <div> and assign position: absolute to the child <div> element. Now the container is aligned for locating the child <div> to bottom-right assign bottom: 0 and right: 0 .

How do you add a hover effect to pseudo-element?

#button:hover:before will change the pseudo-element in response to the button being hovered. If you want to do anything nontrivial to the pseudo-element only, however, you'd be better off putting an actual element into your HTML. Pseudo-elements are rather limited.

Can hover be applied on Div?

You can apply :hover styles to any renderable element on a page. IE6 only supports that pseudo-class on links though.

How do I change the hover effect in HTML?

You can simply use the CSS background-image property in combination with the :hover pseudo-class to replace or change the image on mouseover.


1 Answers

.sidebar_image_box_newsfeed_user_info_comments:hover:before {
   content: "I am new";
}

jsFiddle.

like image 130
alex Avatar answered Sep 28 '22 11:09

alex