<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>line-height值的形式不同子元素的行高也会不同</title>
<style>
.father{font-size: 14px;background:#ccc;}
.son{font-size:26px;} .father1{line-height: 150%;}
.father2{line-height: 1.5;}
.father3{line-height: 1.5em;}
</style>
</head>
<body>
<p>父元素的字体大小为14px,子元素字体大小为26px</p>
<h2>父元素行高为150%时</h2>
<div class="father father1">
父元素font-size:14px;line-height:150%;计算值是 14px * 1.5 = 21px
<div class="son">
子元素font-size:26px;line-height = 父元素行高 = 21px;
</div>
</div>
<h2>父元素行高为1.5时</h2>
<div class="father father2">
父元素font-size:14px;line-height:1.5;计算值是 14px * 1.5 = 21px
<div class="son">
子元素font-size:26px;line-height会继承父元素的1.5,计算得值26px * 1.5 = 39px(子元素的行高);
</div>
</div>
<h2>父元素行高为1.5em时</h2>
<div class="father father3">
父元素font-size:14px;line-height:1.5em;计算值是 14px * 1.5 = 21px
<div class="son">
子元素font-size:26px;line-height = 父元素行高 = 21px;
</div>
</div>
</body>
</html>

微信号“前端大全‘中看到一篇”这可能是史上最全的CSS自适应布局总结“中看到张鑫旭的”学习CSS的瓶颈“,在其中看到一个问题”line-height:150%和line-height:1.5的区别是?“(这引玉深度。。。)特此记录下自己学习的东西,方便以后进行查阅。

line-height的值:normal | <number> | <length> | <percentage>

百分比中的"%":是继承父级元素的距离;

"无单位":是子元素计算各自的行距离

两者的区别:

  • 父元素设置line-height:1.5会直接继承给子元素,子元素根据自己的font-size再去计算子元素自己的line-height。
  • 父元素设置line-height:150%是计算好了line-height值,然后把这个计算值给子元素继承,子元素继承拿到的就是最终的值了。此时子元素设置font-size就对其line-height无影响了。

http://www.cnblogs.com/starof/p/4742323.html

https://www.zhihu.com/question/20394889

https://developer.mozilla.org/en-US/docs/Web/CSS/line-height

http://www.zhangxinxu.com/wordpress/2009/11/css行高line-height的一些深入理解及应用/

line-height:150%/1.5em与line-height:1.5的区别的更多相关文章

  1. 【IntellJ IDEA】idea启动测试类报错Error running 'Test1.test': Command line is too long. Shorten command line for Test1.test or also for JUnit default configuration.

    idea启动测试类报错 Error running 'Test1.test': Command line is too long. Shorten command line for Test1.tes ...

  2. Error running 'xxx': Command line is too long. Shorten command line for xxx

    跑单元测试时,报错如下: Error running 'xxx': Command line is too long. Shorten command line for xxx 解决方案: 在项目所在 ...

  3. IDEA命令行缩短器助你解决此问题:Command line is too long. Shorten command line...

    生命太短暂,不要去做一些根本没有人想要的东西.本文已被 https://www.yourbatman.cn 收录,里面一并有Spring技术栈.MyBatis.JVM.中间件等小而美的专栏供以免费学习 ...

  4. 深入了解line-height(各种单位总结1.5/150%/1.5em)

    默认状态,浏览器使用1.0-1.2 line-height, 这是一个初始值.你可以定义line-height属性来覆盖初始值:p{line-height:140%} 你可以有5种方式来定义line- ...

  5. 转:Canvas标签的width和height以及style.width和style.height的区别

    转自:http://www.cnblogs.com/artwl/archive/2012/02/28/2372042.html 作者:Artwl 背景 今天在博问中看到一个问题:用canvas 的 l ...

  6. JS通过getBoundingClientRect获取的height可能与css设置的height不一致

    发现如果DOM元素有padding-top或者padding-bottom值时, $(dom).height() = dom.style.display + padding-top + padding ...

  7. Ecshop出现问题 includes\lib_main.php on line 1329 includes\lib_base.php on line

    php 5.3版本兼容问题不少,以上函数参数传递问题可以将lib_main.php on line 1329这句 $ext = end(explode('.', $tmp)); 改为 : $extsu ...

  8. d3.svg.line()错误:TypeError: d3.svg.line is not a function

    var line_generator= d3.svg.line() .x(function (d,i) { return i; }) .y(function (d) { return d; }) 错误 ...

  9. offset[Parent/Width/Height/Top/Left] 、 client[Width/Height/Top/Left] 、 Element.getBoundingClientRect()

    开篇提示:以下内容都经个人测试,参考API文档总结,但还是不能保证完全正确,若有错误,还请留言指出___________________________________________________ ...

  10. 将一个文件中的内容,在另一个文件中生成. for line in f1, \n f2.write(line)

    将一个文件中的内容,在另一个文件中生成. 核心语句: for line in f1: f1中的所有一行 f2.write(line)                                  ...

随机推荐

  1. printk函数速率限制

    如果你不小心, 你会发现自己用 printk 产生了上千条消息, 压倒了控制台并且, 可能地, 使系统日志文件溢出. 当使用一个慢速控制台设备(例如, 一个串口), 过量的消息速率也 能拖慢系统或者只 ...

  2. mac nginx php php-fpm

    #the php-fpm config and cammand... cp /private/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf ...

  3. 模拟实现call、apply

    1. 知识点补充: 首先在模拟实现前,先Mark一些我之前不知道的知识: a. eval(string)函数:可计算某个字符串,并执行其中的JavaScript代码 其中,string是必需传入的待计 ...

  4. &卡特兰数学习笔记

    一.关于卡特兰数 卡特兰数是一种经典的组合数,经常出现在各种计算中,其前几项为 : 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 20801 ...

  5. Audio 标签的使用和自己封装一个强大的React音乐播放器

    原文地址:https://www.dodoblog.cn/blog?id=5be84d5c70b2b617f27a4610 这篇文章主要介绍一下博客里的这个音乐播放器是怎么写的 为了更好的表达高深的东 ...

  6. EF 中获取 TableAttribute的值,即数据库中真实的表名

    比如EF中我定义了这样一个实体: [Table(Name = "MyTableName")] public class MyClass { } [Table(Name = &quo ...

  7. 杂项-公司:Amazon

    ylbtech-杂项-公司:Amazon 亚马逊公司(Amazon,简称亚马逊:NASDAQ:AMZN),是美国最大的一家网络电子商务公司,位于华盛顿州的西雅图.是网络上最早开始经营电子商务的公司之一 ...

  8. topology进程结束会不会关闭数据库连接

    测试环境:redhat,oracle 11.2.0.3.0 测试目标:当java进程关闭之后,进程的数据库连接会不会被释放,何时被释放 实验证明:在运行topology前,执行 select coun ...

  9. MessageBox用法

    一 函数原型及参数 function MessageBox(hWnd: HWND; Text, Caption: PChar; Type: Word): Integer; hWnd:对话框父窗口句柄, ...

  10. C++字符串前面加LR

    const std::experimental::filesystem::path symbolsFilename = LR"(d:\fulongtech_git\draing_recogn ...