Skip to content

css部分第二题:行内(inline)元素 设置margin-top和margin-bottom 是否起作用? #12

@airliuchuan

Description

@airliuchuan

答案是起作用
HTML 里的元素分为替换元素(replaced element)和非替换元素(non-replaced element)。
替换元素是指用作为其他内容占位符的一个元素。最典型的就是img,它只是指向一个图像文件。以及大多数表单元素也是替换,例如input等。
非替换元素是指内容包含在文档中的元素。例如,如果一个段落的文本内容都放在该元素本身之内,则这个段落就是一个非替换元素。
向行内非替换元素应用外边距对行高没有影响, 所以看上去是无效的, 对左右是有效果的。
向行内替换元素应用外边距会改变行高, 所以对于img input这样的替换元素, margin-top和margin-bottom是有效的

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions