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 imgto 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样 ...
随机推荐
- Vue之组件的使用
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 报错:org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute statement
org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute statement; SQL [n ...
- Swift中的init方法
摘要:Swift有着超级严格的初始化方法,不仅强化了designated初始化方法的地位,所有不加修饰的init方法都需要在方法中确保非Optional的实例变量被赋值初始化,而在子类中,也强制调用s ...
- 任务五:零基础HTML及CSS编码(二)
面向人群: 零基础或初学者 难度: 简单 重要说明 百度前端技术学院的课程任务是由百度前端工程师专为对前端不同掌握程度的同学设计.我们尽力保证课程内容的质量以及学习难度的合理性,但即使如此,真正决定课 ...
- 牛客OI赛制测试赛2 A 无序组数
链接:https://www.nowcoder.com/acm/contest/185/A来源:牛客网 题目描述 给出一个二元组(A,B) 求出无序二元组(a,b) 使得(a|A,b|B)的组数 无序 ...
- 为ubuntu(18.04)系统启用root用户
1.使用passwd指令为root用户设置密码 2.编辑文件/usr/share/lightdm/lightdm.conf.d/50-ubuntu.confecho 'greeter-show-man ...
- KVM中的网络简介(qemu-kvm)
emu-kvm主要向客户机提供了如下4种不同模式的网络: 1)基于网桥(bridge)的虚拟网卡 2)基于NAT(Network Addresss Translation)的虚拟网络 3)QEMU内置 ...
- LeetCode(27)Remove Element
题目 Given an array and a value, remove all instances of that value in place and return the new length ...
- OO博客作业
第一次多项式的作业感觉还行,同时用c和java写的话也算是一个从c到java的过渡,也算是有了对 java的初步认识,之后的电梯作业出血了一些小BUG,比如有些情况考虑不完善之类的,也算是对面向对象有 ...
- Java基础学习总结(92)——Java编码规范之排版、注释及命名
为使开发人员养成良好的开发习惯,编写可读性强.易维护的程序,结合以往资料,现整理Java编码规范,将之作为开发人员的参照依据. 一.排版 1.相对独立的程序块之间必须加空行 下列情况应该使用一个空行: ...