欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

CSS行高

最编程 2024-02-15 17:10:39
...
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>inline</title> <style> span { background: red; } /* 行高不决定元素本身的高度 */ /* 这里的span元素的高度是由字体的大小决定的,所以这里的span元素的height是17px */ /* 但是行高决定了包含元素的父级元素的高度,所以看到包含span元素的div的高度是30px,是由最大的c3的line-height决定的。 */ /* 另外,如果界面比较小,可以看到div的高度会变化,如果包含了2行,那么是由每一行的line-height最大的相加决定的 */ /* 如果父级加了height,那么父级的height就不由内部元素的line-height决定了 */ .c1 { line-height: 20px; } .c2 { line-height: 8px; } .c3 { line-height: 30px; } .c5 { line-height: 28px; } </style> </head> <body> <div> <!-- 有4个span和一个文本,都是inline元素,inline元素组成的box叫作line box --> <span class="c1">inline box xfg中文</span> <span class="c2">inline box</span> <span class="c3">inline box</span> inline box <span class="c5">inline box</span> </div> </body> </html>