Can you apply a width to a :before/:after pseudo-element (content:url(image))?

You’re not crazy: it is indeed not possible to change the dimensions of an image that is inserted using content, whether it’s inserted with url(), image(), image-set(), element(), or a CSS gradient. The image is always rendered as is. This is known as replaced content, or a replaced element (except we’re not talking about elements … Read more

Change style of pseudo elements in angular2

You can achieve what you need with CSS variables. In your style sheet you can set the background image like this: .featured-image:after { content: ”; background-image: var(–featured-image); } After that you can programmatically set this variable on the same element or higher up in the DOM tree: <div class=”featured-image” [ngStyle]=”{‘–featured-image’: featuredImage}”> More about CSS variables … Read more

Should I use single colons (:) or double colons (::) for before, after, first-letter and first-line pseudo-elements?

For what it’s worth, Selectors 4 now explicitly instructs1 authors to use double colons for all pseudo-elements, including CSS1 and CSS2 pseudo-elements, going forward (emphasis mine): Because CSS Level 1 and CSS Level 2 conflated pseudo-elements and pseudo-classes by sharing a single-colon syntax for both, user agents must also accept the previous one-colon notation for … Read more

CSS data attribute new line character & pseudo-element content value

Here is how this can work. You need to modify your data attribute as follows: [data-foo]:after { content: attr(data-foo); background-color: black; color: white; white-space: pre; display: inline-block; } <div data-foo=’First line &#xa; Second Line’>foo</div> Fiddle Demo: http://jsfiddle.net/audetwebdesign/cp4RF/ How It Works Using \a does not work, but the equivalent HTML entity does, &#xa;. According to the … Read more

Nesting pseudo-elements inside pseudo-elements

The idea of nesting ::before and ::after pseudo-elements has been proposed; see this section of the Generated and Replaced Content module. However, that module has been abandoned pending a complete rewrite, so I wouldn’t hold my breath on this document ever receiving implementation until it’s republished. And even then, whether nesting content pseudo-elements will still … Read more