block vs. inline

block

  • width: 100% by default

  • height: determined by content.

  • ๅฏ่จญๅฎš width, height

  • ๆŽ’็‰ˆๆ™‚ๆœƒไฝ”ๆ“šๆ•ด่กŒ(็”ฑไธŠๅพ€ไธ‹ๆŽ’)

โ€ข inline

  • ไธ่ƒฝ่จญๅฎš width, heightใ€‚(width ็”ฑ content ๆฑบๅฎš) โญ๏ธ

  • ๆŽ’็‰ˆๆ™‚็”ฑๅทฆ่‡ณๅณใ€‚

  • ไธ่ƒฝ่จญๅฎš margin-top, margin-bottomใ€‚โญ๏ธ

โ€ข inline-block

  • ๆŽ’็‰ˆๅƒ inline ๅ…ƒ็ด ็”ฑๅทฆๅพ€ๅณๆŽ’๏ผŒ

  • ไฝ†ๅฏ่จญๅฎš width, height ๅƒ block ๅ…ƒ็ด ใ€‚

  • ๅ…งๅปบ็š„ inline-block ๅ…ƒ็ด ๅ…ฑไบ”ๅ€‹๏ผšimg, button, select, input, textarea

block elements

<address><article><aside><blockquote><canvas><dd><div><dl><dt><fieldset><figcaption><figure><footer><form><h1>-<h6><header><hr><li><main><nav><noscript><ol><p><pre><section><table><tfoot><ul><video>

inline elements

inline elements can't change width and heigh.

<a><abbr><acronym><b><bdo><big><br><button><cite><code><dfn><em><i><img><input><kbd><label><map><object><output><q><samp><script><select><small><span><strong><sub><sup><textarea><time><tt><var>

Last updated