I have a this setup:
<div id="button">Button</div>
and this for CSS:
#button {
color: #fff;
display: block;
height: 25px;
margin: 0 10px;
padding: 10px;
text-indent: 20px;
width: 12%;
}
#button:before {
background-color: blue;
content: "";
display: block;
height: 25px;
width: 25px;
}
Is there a way to give the pseudo element a hover effect such as #button:before:hover {...}
and is it also possible to get the pseudo element to hover in response to another element being hovered like so: #button:hover #button:before {...}
? CSS only would be nice, but also jQuery is fine too.
#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.While CSS won't let you style elements based on elements that come after them, it is usually possible to rig something with the same basic effect by putting :hover on a parent node, i.e.:
You can change the pseudo-element based on hover of the parent:
JSFiddle DEMO
If its just for design purposes I think its better to create Pseudo-Elements on either side of the Rectangle Box and to keep the HTML as simple as possible:
HTML:
CSS:
I've modified the CSS and the result can be seen below:
http://jsfiddle.net/a3ehz5vu/
To clarify, you CAN NOT give
:hover
to a pseudo element. There's no such thing as::after:hover
in CSS as of 2018.