Home > Web Front-end > CSS Tutorial > Why Doesn't CSS :after Work with All HTML Elements?

Why Doesn't CSS :after Work with All HTML Elements?

DDD
Release: 2024-12-24 13:07:30
Original
457 people have browsed it

Why Doesn't CSS :after Work with All HTML Elements?

CSS :after Behavior and Element Compatibility

The CSS :after property extends content after an element in its document flow. However, not all elements seem to support this behavior. Why does :after only work with certain elements?

Answer: Replaced Elements vs. Non-Replaced Elements

According to the CSS specification, only non-replaced elements can have :before and :after properties. Replaced elements have their appearance and dimensions determined externally, including elements like images, plugins, and form controls.

What are Replaced Elements?

Replaced elements include:

  • Images ()
  • Plugins ()
  • Form elements (