Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Impossible to add pseudo element to canvases?

So, I'm currently developing a map editor for a HTML5 game, and while doing so, I wanted to add some pseudo elements to canvases containing thumbnails for building blocks. But after an hour of experimenting and googling without succes, I simply couldn't make the pseudo element appear, I tried applying the css to a div and it appeared, so I guess there is something special going on with the canvas element?

Here is a simple example iv'e set up: http://jsfiddle.net/ZsHGE/

So, I'm turning to you, the all knowing folks here at stackoverflow, for an answer, is it impossible to add pseudo elements to the canvas element?

HTML: 
<!-- No visible pseudo candy :( -->
<canvas class="gimmeSomePseudoCandy" width="50" height="50"> :( </canvas>

<!-- pseudo candy appears! :) -->
<div class="gimmeSomePseudoCandy"></div>

CSS: 
.gimmeSomePseudoCandy:after { content:"Candy"; }
like image 240
Daniel Roth Avatar asked Mar 23 '13 22:03

Daniel Roth


People also ask

Can a span have a pseudo-element?

Use spans if they are wrapping around content, if there's no content, use pseudo-elements.

Can you put HTML elements inside a canvas?

Because browsers will display either a canvas element or HTML controls that you put inside that element, but not both, you must place your controls outside of your canvas elements. To make it appear as though HTML controls are inside a canvas, you can use CSS to place the controls above the canvas.

Can pseudo elements and pseudo classes be combined?

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.

Can I have multiple before pseudo elements for the same element?

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.)


1 Answers

Replaced elements (such as canvas and img) do not currently work with pseudo-elements.

Note. This specification does not fully define the interaction of :before and :after with replaced elements (such as IMG in HTML). This will be defined in more detail in a future specification.

Source

like image 192
alex Avatar answered Oct 16 '22 01:10

alex