Do elements with “position: absolute;” behave as block-level elements?

前端 未结 2 515
深忆病人
深忆病人 2020-12-07 03:44

Are elements with position: absolute; able to have a height, width, padding, etc. without changing it to display: block;

2条回答
  •  星月不相逢
    2020-12-07 04:19

    Short answer: yes.

    Long answer: see http://www.w3.org/TR/CSS21/visuren.html#dis-pos-flo (or SLaks's answer).

    Hovewer, this change refers only to the visual display model of the element. The CSS can't affect the content model of the HTML element since CSS is applied only after the document is parsed into DOM tree. So span element can never have p or div children, no matter which styles are applied to it.

提交回复
热议问题