Let's say I wanted to add a shape (like a checkmark) next to a link after it has been visited, instead of having it just turn purple, using a:after along with a:visited.
I'm unsure if I should select the shape like this:
a:visited:after {
or like this:
a:visited a:after
or
a:visited :after {
(i'm also a bit fuzzy on when I should or shouldn't add a space before a pseudo-element, or does it even matter?)
or perhaps something different?
Right now my css looks like this:
a:visited:after {
/* check mark shape */
content:'\00a0';
color: black;
position: relative;
left:15px;
display:inline-block;
width: 3px;
height: 6px;
border: solid black;
border-width: 0 2px 2px 0;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-o-transform: rotate(45deg);
}
check mark shape code from http://webitect.net/design/webdesign/creating-fancy-bullet-points-with-pure-css3/
Thanks for any help.
There are no special rules around combining pseudo-classes and pseudo-elements, besides the one rule that says there can only be one pseudo-element per complex selector and it must appear at the very end.
You can still chain pseudoselectors.
If you're talking about pseudo-classes, then yes, you can combine them in any order.
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.
You're supposed to use a:visited:after
as you're currently doing. It doesn't work not because of an error in your code, but because the issue lies in the :visited
pseudo-class — it doesn't permit the use of pseudo-elements because of privacy concerns.
So basically, you won't be able to apply your checkmark icon to visited links only.
Regarding this:
(i'm also a bit fuzzy on when I should or shouldn't add a space before a pseudo-element, or does it even matter?)
It does matter, because the space represents a descendant combinator:
The selector a:visited a:after
represents the :after
pseudo-element of an a
that is a descendant of another a
which is a visited link, which in HTML doesn't quite make sense.
The selector a:visited :after
is similar to a:visited a:after
, except it represents :after
of any kind of descendant of a:visited
.
It can be rewritten as a:visited *:after
. See the universal selector in the spec.
By omitting the space, you're applying the pseudo-element directly to the element represented by the selector before it, which in your case is a:visited
, not any of its descendants.
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