inline无法设置尺寸(宽度、高度),它的尺寸是有它的内容决定的,有多少内容就占多少空间。即使设置了尺寸,也不会生效。
block, inline-block则可以设置尺寸。
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Document</title> | |
| <link rel="stylesheet" href="style.css"> | |
| </head> | |
| <body> | |
| <div>1</div> | |
| <div></div> | |
| <div></div> | |
| </body> | |
| </html> |
inline无法设置尺寸(宽度、高度),它的尺寸是有它的内容决定的,有多少内容就占多少空间。即使设置了尺寸,也不会生效。
block, inline-block则可以设置尺寸。
| div { | |
| width: 1em; | |
| height: 1em; | |
| } | |
| div:nth-of-type(1) { | |
| display: inline; | |
| background-color: red; | |
| } | |
| div:nth-of-type(2) { | |
| display: block; | |
| background-color: green; | |
| } | |
| div:nth-of-type(3) { | |
| display: inline-block; | |
| background-color: blue; | |
| } |