Why the :before and :after pseudo-elements work only in Firefox?

眉间皱痕 提交于 2019-11-28 09:31:56

问题


I've created a select list with options having :after and :before pseudo-elements - DEMO

option:after, option::before {
    content: " ";
    height: 5px;
    width: 5px;
    background: #c00;
    border-radius: 5px;
    display: inline-block;
}

However this works in Firefox only and no other browser.

As it stated on W3C, MDN, SitePoint the :after is a "pseudo-element rendered after the matched element and used to add cosmetic content" and nobody states any restriction about elements it can't be applied to.

Question - why all the browsers (except FF) can't properly display the pseudo-elements? Any documentation is greatly appreciated.


回答1:


Whether there is a restriction is undefined, hence the inconsistent behavior. This is mentioned at the bottom of the relevant section in the spec:

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.

Most HTML form elements are considered replaced elements, including select and option.




回答2:


Have you read this: :before and :after pseudo elements on html tag is wonky in Chrome ?

The accepted answer said that is an issue in Chrome:

https://code.google.com/p/chromium/issues/detail?id=75544



来源:https://stackoverflow.com/questions/11903273/why-the-before-and-after-pseudo-elements-work-only-in-firefox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!