Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS :after, content: having two values?

I've got CSS on my links depending what type of link it is. In this case it's password protected, and external link.

So I've got CSS like this:

a.external-link:after { padding-left: 2px; content: url(../images/icon-external-link.gif); }
a.restricted-link:after { padding-left: 2px; content: url(../images/icon-lock.png);}

However when I try something like this:

<a class="external-link restricted-link" href="some link">Some Link</a>

It only displays the last icon, in this case the icon-lock.png. Which makes sense, since the content value can only be set once not combined, so the last class declaration is overwriting it. Is there anyway to combine these two so I can mix and match these link classes easily (I've got 4 total). I don't want to make separate classes/images for each combo.

like image 946
SventoryMang Avatar asked Jan 05 '11 17:01

SventoryMang


People also ask

Can CSS have two after?

You can combine several CSS pseudo-elements for one element. However, you cannot use CSS ::after two times or ::before two times. In the example below, the first letter of <div> is green and has x-large font size. The first line of <div> element is red and has small capital letters.

Can you have multiple after elements?

1, an element can only have at most one of any kind of pseudo-element at any time. (This means an element can have both a :before and an :after pseudo-element — it just cannot have more than one of each kind.)

What is :: before and :: after?

The ::before selector inserts something before the content of each selected element(s). Use the content property to specify the content to insert. Use the ::after selector to insert something after the content.

What does :: After mean in CSS?

In CSS, ::after creates a pseudo-element that is the last child of the selected element. It is often used to add cosmetic content to an element with the content property. It is inline by default.


1 Answers

Hate to break it to you, but you're going to have to make separate classes/images for each combo. Especially as there would be no way of knowing which content should go first.

a.external-link.restricted-link:after
{
  content: url(ext) url(res);
}

vs

a.external-link.restricted-link:after
{
  content: url(res) url(ext);
}
like image 117
zzzzBov Avatar answered Oct 12 '22 12:10

zzzzBov