http://jsfiddle.net/nicktheandroid/k93ZK/2/
This should be really simple, I just don't understand why it's not working. When hovering over the :before
it should change it's opacity to 1, but it doesn't. Why?
p {
padding-top:15px;
position:relative;
}
p:before {
display:block;
width:55px;
height:55px;
content: 'hello';
background:#fff;
padding:5px 10px;
position:absolute;
right:0;
opacity:.5;
-webkit-transition: all 0.3s ease-in-out;
}
p:before:hover {
opacity:1;
bakcground:#000;
}
EDIT: I'm using Chrome.
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.
Moreover, to check if your :hover event is setting the desired css property or not you can force-trigger the hover event from chrome (by checking hover in styles> :hov> hover red marked in image) and check if the :hover CSS property is working or not.
#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.
The CSS ::before selector inserts content before a selected element. CSS :after inserts content after a specified element. These selectors are commonly used to add text before or after a paragraph or a link.
Instead of p:before:hover
, you need p:hover:before
.
See: http://jsfiddle.net/k93ZK/3/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With