1.元素高度从何而来?是由里面的文字撑开的?

<!DOCTYPE html>
<html lang="en">
<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>Document</title>
<style>
*{margin: 0;padding: 0;}
.test1{font-size: 0;line-height: 36px;border: 1px solid red;background: gray;}
.test2{font-size: 36px;line-height: 0;border: 1px solid red;background: gray;}
</style>
</head>
<body>
<div class="test1">测试</div>
<br>
<div class="test2">测试</div>
<!-- 从效果图中可看出,元素高度是由line-height决定的 -->
</body>
</html>

2.如果行框盒子里面有多个不同高度的内联盒子?

<!DOCTYPE html>
<html lang="en">
<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>Document</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<style>
*{margin: 0;padding: 0;}
.em{line-height: 80px;}
</style>
</head>
<body>
<div id="app">
这是一行普通的文字,这里有个<em class="em">em</em>标签。
</div>
<!-- 如果行框盒子里面有多个不同行高的内联盒子?
原则上是由最高的那个内联盒子的高度决定的,但如vertical-align这样的属性可能会改变行框盒子高度
-->
</body>
</html>

3.父级元素line-height:1.5与line-height:150%/1.5em的区别

在计算上无差别,都是fontSize*1.5,但实际上有区别

<!DOCTYPE html>
<html lang="en">
<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>Document</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<style>
*{margin: 0;padding: 0;}
.app{line-height: 1.5}
/* 当父级元素line-height:1.5时,子元素的高度是用自己的fontSize*1.5得到自己的高度 */
.val{font-size: 60px}
</style>
</head>
<body>
<div class="app">
<p>line-height:1.5</p>
<p class="val">我的font-size为60px</p>
</div>
</body>
</html>

<!DOCTYPE html>
<html lang="en">
<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>Document</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<style>
*{margin: 0;padding: 0;}
.app{line-height: 150%}
/* 当父级元素line-height:150时,子元素的高度是用父级的fontSize*1.5得到自己的高度 */
.val{font-size: 60px}
</style>
</head>
<body>
<div class="app">
<p>line-height:1.5</p>
<p class="val">我的font-size为60px</p>
</div>
</body>
</html>

line-height的高度机理的更多相关文章

  1. html的height:100%;高度是多少

    html的height:100%;高度是多少 html设置height:100%;表示一屏高度,类似于100vh.未设置则根据子元素的高度来自适应高.在实际应用中,设置页面高度为1屏幕高度通常设置: ...

  2. 使用 <embed> 标签显示 flash文件(swf)格式 ,如何设置 width 和 height 宽度,高度.

    1. embed 标签 支持  .swf 格式.     .flv 的不支持. 2. 通常情况下, 网站中上传 多个 flash文件. 它的默认大小是不一样的. 而且 可以 宽度 大于 高度(横向的) ...

  3. [LeetCode] Queue Reconstruction by Height 根据高度重建队列

    Suppose you have a random list of people standing in a queue. Each person is described by a pair of ...

  4. Div Height设置高度后不能自适应

    解决方法$("#div1").css("height", "");

  5. div height 自适应高度 占满剩余高度的方法

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. [LeetCode] 406. Queue Reconstruction by Height 根据高度重建队列

    Suppose you have a random list of people standing in a queue. Each person is described by a pair of ...

  7. How to Take Control of Your Line Height in Outlook.com

    Reference to: http://www.emailonacid.com/blog/details/C13/line_height_and_outlook.com

  8. 深入了解css的行高Line Height属性

    什么是行间距? 古时候我们使用印刷机来出来文字.印刷出来的每个字,都位于独立的一个块中. 行间距,即传说中控制两行文字垂直距离的东东.在CSS中,line-height被用来控制行与行之间垂直距离. ...

  9. 浅析CSS中的BFC和IFC

    1. 为什么会有BFC和IFC 首先要先了解两个概念:Box和formatting context: Box:CSS渲染的时候是以Box作为渲染的基本单位.Box的类型由元素的类型和display属性 ...

随机推荐

  1. flutter 自定义输入框组件

    一.组件分析 ui如下 根据UI分析我们需要提取哪些是动态的,可以通过传递参数得到不同的结果? 1.左侧icon 2.输入的文本 3.是否是密码框 4.输入框的控制器:如何时时得到输入框的值 二.快速 ...

  2. python做数据驱动

    python代码如下: import unittestfrom openpyxl import load_workbookfrom openpyxl.styles import Fontfrom op ...

  3. Lists.newArrayList的一个小坑

    把一个用户ID转换成List存储,最开始我使用的方法是: // 用户ID Integer userId = 120; // id 转 List List<integer> userIds ...

  4. LeetCode 5 最长对称串

    LeetCode 5 最长对称串 最早时候做这道题的时候还是用Java写的,用的是字符串匹配的思路,一直Time Limit Exceeded.甚至还想过用KMP开优化子串查找. public cla ...

  5. JDK8 HashMap--treeify()树形化方法

    /*创建红黑树*/ final void treeify(Node<K,V>[] tab) { TreeNode<K,V> root = null;// 定义红黑树根节点roo ...

  6. python导入.py文件

    1.from . import D # 导入A.B.D 2.from .. import E # 导入A.E 3.from ..F import G # 导入A.F.G,.. 和 F是连着的,中间没有 ...

  7. Oracle VM Virtual 安装 ubuntu 后设置全屏

    按照正常流程在vm中安装了ubuntu之后,发现ubuntu系统无法全屏显示,解决途径如下: 1.在vm中点击设置 2.选择“安装增强功能” 3.正常情况下,我们可以在桌面看到一个光盘图标(文件名:V ...

  8. Debian setup the time

    sudo gedit /etc/default/hwclock将 井HWCLOCKACCESS=yes 和 井HCTOSYS_DEVICE=rtc0 前的 井 符号去掉,再改 rtc0 为 rtc1 ...

  9. day1:java学习第一天之eclipse安装

    选择开发语言的学习其实不用纠结,如果你说自己是做开发的,连最流行的开发语言都不会,好像说不过去,并且最流行也说明用的人多,优秀的人也会,自己要提高要多向优秀的人学习.想明白这点其实选择就好说了,再一个 ...

  10. 【winform】serialPort 串口

    一. 1.串口通信简单实现 该来的总会来的,学做硬件的,串口这个东西必须得门清. 俗话说的好,不会做串口助手的电子工程师不是好程序员.