Home > Web Front-end > CSS Tutorial > Why Don't `:before` and `:after` Pseudo-elements Work with `` Elements?

Why Don't `:before` and `:after` Pseudo-elements Work with `` Elements?

DDD
Release: 2024-12-19 01:36:17
Original
700 people have browsed it

Why Don't `:before` and `:after` Pseudo-elements Work with `` Elements?

Addressing the Functionality of Pseudo Elements with Image Elements

In an attempt to enhance functionality, this question explores why pseudo elements like :before and :after do not interact with image () elements as they do with other tags such as divs and spans. To illustrate the problem, consider the following HTML and CSS:

<img src="http://0.gravatar.com/avatar/this-is-not-a-hash" alt=""/>
Copy after login
img:before {
  content: "hello";
}
Copy after login

Upon examining this code in browsers like Chrome 13 and Firefox 6, it becomes evident that no expected changes occur with the image element. This behavior contrasts with the compatibility exhibited by div and span elements.

Diving into the specifications, we encounter this excerpt:

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.
Copy after login

This statement suggests an incomplete definition for the interaction between pseudo elements and image elements, implying their current incompatibility. For further insights into this matter, refer to another response on this platform.

The above is the detailed content of Why Don't `:before` and `:after` Pseudo-elements Work with `` Elements?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template