Is there any guide on “When to use display:block when :inline and when :inline-block” and why?

前端 未结 4 1132
甜味超标
甜味超标 2020-12-23 15:40

Do you know any good article on \"When to use display:block when :inline and when :inline-block\" and why?

and when we will ha

4条回答
  •  梦毁少年i
    2020-12-23 16:20

    The use cases for block and inline are pretty obvious. Use inline if you want to apply a style to a short span of text (e.g. a few words), and use block for rectangles areas with width/height.

    As for inline-block, it's used naturally for images. It's useful when you want to have small blocks flowing left-to-right, top-to-bottom like regular text, but still have them like blocks.

    Note: in 90% of cases you don't need to specify the display property, just use appropriate elements with classes, like or for inline,

    or

    for blocks. The main way it comes into play is when hiding stuff with Javascript, you just need to revert the element to its original/natural display attribute.

提交回复
热议问题