Does :before not work on img elements?

后端 未结 12 2242
眼角桃花
眼角桃花 2020-11-22 01:46

I\'m trying to use the :before selector to place an image over another image, but I\'m finding that it simply doesn\'t work to place an image before an im

12条回答
  •  无人及你
    2020-11-22 02:36

    I think the best way to look at why this doesn't work is that :before and :after insert their content before or after the content within the tag you're applying them to. So it works with divs or spans (or most other tags) because you can put content inside them.

    :before Content :after

    However, an img is a self-contained, self-closing tag, and since it has no separate closing tag, you can't put anything inside of it. (That would need to look like Content, but of course that doesn't work.)

    I know this is an old topic, but it pops up first on Google, so hopefully this will help others learn.

提交回复
热议问题