css中高度比img多出4px的问题
一句话概括:为什么<a>标签比里面的img高度多出4px 的问题,主要还是由于 img是inline element, it's height is caculated differently as related to the
default line-height value. On inline elements, the line-height css property specifies the height that is used in the calculation of the line box height.
on block level elements, line-height specifies the minimal height of line boxes within the element.
原文:
----------------------------------------------------------------------------------
Trying adding:
img { display: block; }
to your CSS. Since an <img>
is an inline element by default, it's height is calculated differently as related to the default line-height value.
On inline elements, the line-height CSS property specifies the height that is used in the calculation of the line box height.
On block level elements, line-height specifies the minimal height of line boxes within the element.
Source: https://developer.mozilla.org/en/CSS/line-height
That does indeed fix it. Could you elaborate as to why it makes a difference? (I'm not holding out on accepting - SO won't let me until 11 more minutes have passed) – Chris Jun 20 '12 at 19:25
|
|||
@Chris - it's the reason I had given you: the
img has an implicit line-height assigned to it, which gives it some vertical breathing room. Since line-height only applies to inline elements, setting the img to display: block removes the line-height . – Joseph Silber Jun 20 '12 at 19:30 |
|||
|
@Joseph - I hadn't seen your response when I made the above request. Since they are basically achieving the exact same thing directly and indirectly, there's not much to choose between the answers. It only seems fair to accept the answer that arrived first, but thanks for your explanation. – Chris Jun 20 '12 at 19:34
|
||
|
This also works with
inline-block . Thanks for the explanation. |
css中高度比img多出4px的问题的更多相关文章
- css中的流,元素,基本尺寸
流 元素 基本尺寸 流之所以影响整个css世界,是因为它影响了css世界的基石 --HTML HTML 常见的标签有虽然标签种类繁多,但通常我们就把它们分为两类: 块级元素(block-level e ...
- css中“~”和“>”
css中“~” element1~element2 选择器匹配 出现在 element1 后面的 element2 .element1 和 element2 这两种元素必须具有相同的父元 ...
- css中".",",",“~”和“>”符号的意义
css中“~” element1~element2 选择器匹配出现在element1后面的element2.element1和element2这两种元素必须具有相同的父元素,但element2不必紧跟 ...
- css中height 100vh的应用场景,动态高度百分比布局,浏览器视区大小单位
css中height 100vh的应用场景,动态高度百分比布局,浏览器视区大小单位 height:100vh 一些只能vw, vh才能完成的应用场景: 1. 场景之:元素的尺寸限制 vw vh 主要是 ...
- css中如何实现左边的高度随着右边改变而改变
css中如何实现左边的高度随着右边改变而改变 html结构: <div class="main"> <div class="main_left" ...
- CSS 中的高度百分比
CSS 中可以使用%来给定指定元素的大小,也就是高度.宽度.margin,padding 等等,但是相信很多人都对百分比表示法的具体含义并不清楚,那么不懂就练,毕竟是检验真理的唯一标准(考研党举个手我 ...
- 对CSS中的Position、Float属性的一些深入探讨
对CSS中的Position.Float属性的一些深入探讨 对于Position.Float我们在平时使用上可以说是使用频率非常高的两个CSS属性,对于这两个属性的使用上面可能大多数人存在一些模糊与不 ...
- 浅析CSS中的BFC和IFC
1. 为什么会有BFC和IFC 首先要先了解两个概念:Box和formatting context: Box:CSS渲染的时候是以Box作为渲染的基本单位.Box的类型由元素的类型和display属性 ...
- CSS中一些常见的兼容性问题
CSS中一些兼容性问题就是浏览器兼容,而这些浏览器兼容问题主要是Ie和FF之间的争斗. CSS hack中的一些事: 我们为了让页面形成统一的效果,要针对不同的浏览器或不同版本写出对应可解析的CSS样 ...
随机推荐
- 【前端】pid2children iview tree json
<script> import inBody from '../inBody' export default { components:{ inBody } ,data () { retu ...
- 为什么我的 app:actionViewClass="android.widget.SearchView"和app:showAsAction="ifRoom|collapseActionView"才有
http://blog.csdn.net/cdnight/article/details/48029911 <item android:id="@+id/action_search&q ...
- postman使用--发送请求
概述 上节讲了下接口的基础,从现在来学习怎么测接口.当然,测试接口有很多的工具,比如postman,jmeter等等,或者用代码测试,如果是做接口自动化我当然会选python,如果是调试接口,我特别喜 ...
- ios字体简单设定
UILabel *lable = [[UILabel alloc] init]; label.font = [];
- IOS学习笔记3—Objective C—简单的内存管理
今天简述一下简单的内存管理,在IOS5.0以后Apple增加了ARC机制(Automatic Reference Counting),给开发人员带来了不少的方便,但是为了能更好的理解IOS内存管理机制 ...
- 从多表连接后的select count(*)看待SQL优化
从多表连接后的select count(*)看待SQL优化 一朋友问我,以下这SQL能直接改写成select count(*) from a吗? SELECT COUNT(*) FROM a LEFT ...
- mysql 5.7 windows zip安装
mysql 官网下载windows zip 安装包 并解压 (D:wampmysql-56-winx64) 添加path D:wampmysql-5722-winx64bin 创建data目录 D:\ ...
- CentOS6.8下安装Docker
原文章链接https://www.cnblogs.com/baolong/p/5743420.html. 由于在自己安装的虚拟机上打开linux终端命令行输入uname -a 以及cat /etc/r ...
- Cable master 求电缆的最大长度(二分法)
Description Inhabitants of the Wonderland have decided to hold a regional programming contest. The J ...
- str内部方法释义
1. __add__:字符串拼接 [示例]:>>> str1=‘good’>>> str1.__add__(‘morning’)>>> ‘good ...