因此,我目前正在为一款 HTML5 游戏开发 map 编辑器,在此过程中,我想向包含积木缩略图的 Canvas 添加一些伪元素。但是经过一个小时的试验和谷歌搜索都没有成功,我根本无法让伪元素出现,我尝试将 css 应用于 div 并且它出现了,所以我猜 canvas 元素有什么特别之处?
这里是一个简单的例子,我已经设置好了: http://jsfiddle.net/ZsHGE/
所以,我求助于 stackoverflow 上所有知识渊博的人,寻求答案,是否不可能向 canvas 元素添加伪元素?
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"; }
最佳答案
替换元素(例如canvas
和img
)目前不能与伪元素一起使用。
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.
关于css - 无法将伪元素添加到 Canvas ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15593043/