line-height:150%/1.5em与line-height:1.5的区别
<!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的区别的更多相关文章
- 【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 ...
- 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 解决方案: 在项目所在 ...
- IDEA命令行缩短器助你解决此问题:Command line is too long. Shorten command line...
生命太短暂,不要去做一些根本没有人想要的东西.本文已被 https://www.yourbatman.cn 收录,里面一并有Spring技术栈.MyBatis.JVM.中间件等小而美的专栏供以免费学习 ...
- 深入了解line-height(各种单位总结1.5/150%/1.5em)
默认状态,浏览器使用1.0-1.2 line-height, 这是一个初始值.你可以定义line-height属性来覆盖初始值:p{line-height:140%} 你可以有5种方式来定义line- ...
- 转:Canvas标签的width和height以及style.width和style.height的区别
转自:http://www.cnblogs.com/artwl/archive/2012/02/28/2372042.html 作者:Artwl 背景 今天在博问中看到一个问题:用canvas 的 l ...
- JS通过getBoundingClientRect获取的height可能与css设置的height不一致
发现如果DOM元素有padding-top或者padding-bottom值时, $(dom).height() = dom.style.display + padding-top + padding ...
- 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 ...
- 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; }) 错误 ...
- offset[Parent/Width/Height/Top/Left] 、 client[Width/Height/Top/Left] 、 Element.getBoundingClientRect()
开篇提示:以下内容都经个人测试,参考API文档总结,但还是不能保证完全正确,若有错误,还请留言指出___________________________________________________ ...
- 将一个文件中的内容,在另一个文件中生成. for line in f1, \n f2.write(line)
将一个文件中的内容,在另一个文件中生成. 核心语句: for line in f1: f1中的所有一行 f2.write(line) ...
随机推荐
- LeetCode 19.删除链表的倒数第N个节点(Python)
题目: 给定一个链表,删除链表的倒数第 n 个节点,并且返回链表的头结点. 示例: 给定一个链表: 1->2->3->4->5, 和 n = 2. 当删除了倒数第二个节点 ...
- python3 selenium 超时停止加载,并且捕捉异常, 进行下一步【亲测有效】
from selenium import webdriver import os import re class GetPage: def __init__(self, url_path): self ...
- 二分图——poj2239
水题 /* n门课,每门课有一个时间t 要求最大的n->t的匹配 */ #include<iostream> #include<cstring> #include< ...
- pytorch基础2
下面是常见函数的代码例子 import torch import numpy as np print("分割线---------------------------------------- ...
- System.Web.Mvc.HttpStatusCodeResult.cs
ylbtech-System.Web.Mvc.HttpStatusCodeResult.cs 1.程序集 System.Web.Mvc, Version=5.2.3.0, Culture=neutra ...
- Hadoop 初体验
Hadoop 是一个基于谷歌发表的几篇论文而开发的一个分布式系统基础架构,用户可在不了解分布式底层细节的情况下,开发分布式程序.充分利用集群的威力进行高速运算和存储.Hadoop现在已经成了大数据的代 ...
- 如何提高Axure设计的效率 提高Axure设计效率的10条建议
如何更有效率的使用axure,这是新手需要掌握的技能.本文作者从实际经验中归纳出来的十条建议十分值得学习,转载分享给大家: Axure 是创建软件原型的快速有力的工具.上手很容易,但是,其中存在一个危 ...
- Python爬取b站任意up主所有视频弹幕
爬取b站弹幕并不困难.要得到up主所有视频弹幕,我们首先进入up主视频页面,即https://space.bilibili.com/id号/video这个页面.按F12打开开发者菜单,刷新一下,在ne ...
- TKmybatis的框架介绍及使用方法
最近项目使用了SpringBoot+TKMytis框架,期间遇到一些问题,顺便记一下. 一.框架配置 配置的话非常简单,我用的是SpringBoot,直接引入: <dependency> ...
- Nmap扫描原理(上)
转自:https://blog.csdn.net/qq_34398519/article/details/89055991 Nmap是一款开源免费的网络发现(Network Discovery)和安全 ...