input
select
img
单标签不支持伪元素
首先我们要知道伪元素有哪些:
::after ::before ::first-letter ::fist-line (单双冒号皆可)
::selection ::backdrop (仅双冒号)
伪元素虽然强大,但是还是有一些特定的标签是不支持伪元素 before 和 after 的。
诸如 img 、input、iframe,这几个标签是不支持类似 img::before 这样使用。
究其原因,要想要标签支持伪元素,需要这个元素是要可以插入内容的,也就是说这个元素要是一个容器。而 input,img,iframe 等元素都不能包含其他元素,所以不能通过伪元素插入内容。
Authors specify the style and location of generated content with the :before and :after pseudo-elements. As their names indicate, the :before and :after pseudo-elements specify the location of content before and after an element's document tree content. The 'content' property, in conjunction with these pseudo-elements, specifies what is inserted.
伪元素介绍:https://developer.mozilla.org/zh-CN/docs/Web/CSS/pseudo-elements
note: W3C规范中,伪元素用双冒号用于与伪类(但冒号)区别
only works on elements that have a (document tree) content. input has no content, as well as img or br
只在有content的元素中可以引用伪元素。 如input,img,br 无法添加内容的标签就没有办法引用伪元素
Most helpful comment
首先我们要知道伪元素有哪些:
::after ::before ::first-letter ::fist-line (单双冒号皆可)
::selection ::backdrop (仅双冒号)
伪元素虽然强大,但是还是有一些特定的标签是不支持伪元素 before 和 after 的。
诸如 img 、input、iframe,这几个标签是不支持类似 img::before 这样使用。
究其原因,要想要标签支持伪元素,需要这个元素是要可以插入内容的,也就是说这个元素要是一个容器。而 input,img,iframe 等元素都不能包含其他元素,所以不能通过伪元素插入内容。