Replaced elements - CSS: Cascading Style Sheets 编辑
In CSS, a replaced element is an element whose representation is outside the scope of CSS; they're external objects whose representation is independent of the CSS formatting model.
Put in simpler terms, they're elements whose contents are not affected by the current document's styles. The position of the replaced element can be affected using CSS, but not the contents of the replaced element itself. Some replaced elements, such as <iframe>
elements, may have stylesheets of their own, but they don't inherit the styles of the parent document.
The only other impact CSS can have on a replaced element is that there are properties which support controlling the positioning of the element's content within its box. See Controlling object position within the content box for further information.
Replaced elements
Typical replaced elements are:
Some elements are treated as replaced elements only in specific cases:
HTML spec also says that an <input>
element can be replaced, because <input>
elements of the "image"
type are replaced elements similar to <img>
. However, other form controls, including other types of <input>
elements, are explicitly listed as non-replaced elements (the spec describes their default platform-specific rendering with the term "Widgets").
Objects inserted using the CSS content
property are anonymous replaced elements. They are "anonymous" because they don't exist in the HTML markup.
Using CSS with replaced elements
CSS handles replaced elements specifically in some cases, like when calculating margins and some auto
values.
Note that some replaced elements, but not all, have intrinsic dimensions or a defined baseline, which is used by some CSS properties, such as vertical-align
. Only replaced elements can ever have intrinsic dimensions.
Controlling object position within the content box
Certain CSS properties can be used to specify how the object contained within the replaced element should be positioned within the element's box area. These are defined by the CSS Images Module Level 3 and CSS Images Module Level 4 specifications:
object-fit
- Specifies how the replaced element's content object should be fitted to the containing element's box.
object-position
- Specifies the alignment of the replaced element's content object within the element's box.
See also
- HTML Spec
- CSS Key Concepts: CSS syntax, at-rule, comments, specificity and inheritance, the box, layout modes and visual formatting models, and margin collapsing, or the initial, computed, resolved, specified, used, and actual values. Definitions of value syntax, shorthand properties and replaced elements.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论