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"; }
Use spans if they are wrapping around content, if there's no content, use pseudo-elements.
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.
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.
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.)
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 asIMG
in HTML). This will be defined in more detail in a future specification.
Source
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