关于overflow: hidden;的一个诡异问题
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1,minimum-scale=1,maximum-sacle=1,user-scalable=no">
<style>
*{
padding: ;
margin: ;
}
.test{
width: 102px;
margin-top: 100px;
margin-left: 100px;
}
.test ul{
overflow: hidden;
}
.test ul li{
/*display: block;*/
float: left;
border: 1px solid #;
}
.test1{
display: block;
width: 100px;
height: 50px;
line-height: 50px;
background-color: red;
overflow: hidden;
}
.test1 p{
float: left;
}
</style>
</head>
<body>
<div class="test">
<ul>
<li>
<div class="test1">
<p>我发的是</p>
</div>
</li>
</ul>
</div>
</body>
</html>

给li里面的div设置overflow: hidden就会西湖此案这个问题
如果去掉overflow: hidden或者给li设置display:block或者display:inline-block就正常,不懂为什么
下面这个是网上找到的,但是和我遇到的问题还是有差距
转:https://my.oschina.net/u/214483/blog/663133
工作中遇到的一个问题,设置inline-block元素的overflow:hidden意外增加元素总体高度。
描述如下:
设 A为子容器,B为父容器。
A设置为inline-block,并且overflow为hidden,A高度为23,B高度为30。
A设置为block,A高度为23,B高度为23。
通过stackoverflow找到原因(http://stackoverflow.com/questions/22421782/css-overflow-hidden-increases-height-of-container),摘抄如下:
Let me explain to you why this is happening.
According to CSS 2.1 Specs,
The baseline of an 'inline-block' is the baseline of its last line box in the normal flow, unless it has either no in-flow line boxes or if its 'overflow' property has a computed value other than 'visible', in which case the baseline is the bottom margin edge.
To explain in simple words,
i) If inline-block in question has its overflow property set to visible (which is by default so no need to set though). Then its baseline would be the baseline of the containing block of the line. ii) If inline-block in question has its overflow property set to OTHER THAN visible. Then its bottom margin would be on the baseline of the line of containing box.
So, in your case the inline-block cell has overflow:hidden (not VISIBLE), so its margin-bottom, the border of cell is at the baseline of the container element container.
That is why the element cell looks pushed upwards and the height of container appears increased. You can avoid that by setting cell to display:block.
翻译如下:
'inline-block'的baseline是其在normal flow中的最后一个line box的baseline,除非它没有in-flow line boxes,或者其‘overflow’属性不等于‘visible’,这种情况下,其baseline位于bottom margin边上。
解释如下:
i) 如果inline-block的overflow设为visible(默认属性),则其baseline是当前行的containing block的baseline。
ii) 如果overflow设为其他,则其bottom margin位于前行的containing block的baseline;
我们这种情况下,inline-block元素的overlow:hidden,所以元素的底部边框在父元素的baseline。
因此高度才会看起来增加了。
可以将inline-block设为block,即可解决问题。

关于overflow: hidden;的一个诡异问题的更多相关文章
- 移动端浏览器body的overflow:hidden并没有什么作用
今天突然遇到一个问题,使用li模拟select,但是碰到一个很尴尬的问题,给body加了overflow:hidden,但是body并没有禁止滚动条,滚动条依旧顺滑. <!DOCTYPE htm ...
- 特别的表格(overflow:hidden的一个小应用)
做多个li,对各个边的边框有不同的要求,三层盒子,第一层盒子放li,设置右边和下边的虚线边框,浮动,第二层盒子ul设置宽度使li排列,第三层盒子最大的盒子,使用overflow:hidden,宽度高度 ...
- overflow:hidden的另一层含义
overflow:hidden这个CSS样式是大家常用到的CSS样式,但是大多数人对这个样式的理解仅仅局限于隐藏溢出,而对于清除浮动这个含义不是 很了解.一提到清除浮动,我们就会想到另外一个CSS样式 ...
- CSS 的overflow:hidden 属性详细解释
overflow:hidden这个CSS样式是大家常用到的CSS样式,但是大多数人对这个样式的理解仅仅局限于隐藏溢出, 而对于清除浮动这个含义不是很了解.一提到清除浮动,我们就会想到另外一个CSS样式 ...
- 解决 border-radius 元素在应用了 transform 的子元素 时overflow:hidden 失效的问题
受大家启迪,于是最近深入研究了一下Css3中的一些属性.之中也是碰到了个不为我知的问题,在这里特此总结并与大家分享. 问题重现:在父元素上应用了 border-radius 的圆角属性.加上 ove ...
- td内容自动换行 ,td超过宽度显示点点点… , td 使用 overflow:hidden 无效,英文 数字 不换行 撑破div容器
我们可以先给表格 table上 固定一个宽度 不让表格撑破 width: 747px; table-layout:fixed; 然后我们在td上加上如下样式 style="width:100 ...
- overflow:hidden清除浮动原理解析及清除浮动常用方法总结
最近在看<CSS Mastery>这本书,里面有用overflow:hidden来清理浮动的方法.但是一直想不明白为什么能够实现清除浮动,查阅了网络上的解释,下面来总结一下. 一.首先来想 ...
- border-radius导致overflow:hidden失效问题。
如果一个父元素设置了overflow:hidden属于的同时还设置了border-radius属性,那么如果想隐藏超出的子元素,四个圆角处会出现超出圆角依然显示的bug: 一种方法是运用-webkit ...
- 关于css中overflow:hidden的使用
overflow:hidden有两个用处经常用到: 1.通过设定自身的高度,加上overflow:hidden可以隐藏超过容器本身的内容: 但是,小编在以往的使用中,发现了一个问题,只要父级容 ...
随机推荐
- SVN for Mac
SVN for Mac https://www.wikihow.com/Install-Subversion-on-Mac-OS-X https://subversion.apache.org/pac ...
- Fitts’ Law / 菲茨定律(费茨法则)
Fitts’ Law / 菲茨定律(费茨法则) 补充一张雅虎ued绘制的关于Fitts’ Law的Q版小漫画,先初步了解下: Fitts’ Law / 菲茨定律(费茨法则) Fitts’ Law ...
- 【版本管理】git分支管理
创建与合并分支: 首先,我们创建dev分支,然后切换到dev分支: git checkout -b dev,命令加上-b参数表示创建并切换, 相当于以下两条命令: git branch dev: gi ...
- sqlbulkcopy 批量更新 数据库
转载: http://blog.csdn.net/wangzh300/article/details/7382506 private static void DataTableToSQLServer( ...
- 【BZOJ1449】[JSOI2009]球队收益(网络流,费用流)
[BZOJ1449][JSOI2009]球队收益(网络流,费用流) 题面 BZOJ 洛谷 题解 首先对于一支队伍而言,总共进行多少场比赛显然是已知的,假设是\(n_i\)场,那么它的贡献是:\(C_i ...
- 【BZOJ1056】[HAOI2008]排名系统(Splay)
[BZOJ1056][HAOI2008]排名系统(Splay) 题面 BZOJ 洛谷 题解 \(Splay\)随便维护一下就好了,至于名字什么的,我懒得手写哈希表了,直接哈希之后拿\(map\)压. ...
- 【BZOJ4500】矩阵(差分约束)
[BZOJ4500]矩阵(差分约束) 题面 BZOJ 然而权限题 题解 显然拆分行和列.不妨设这一行/列总共加减的值是\(p\),那么每一个限制就是两个数的和为一个特定的数.这样子不好做,反正是一个二 ...
- 【转】在windows中使用Intellij Idea时选择自定义的64位JVM
原文地址:https://www.iflym.com/index.php/code/201404190001.html 本文英文原文自:https://intellij-support.jetbrai ...
- mysql新版本问题
异常错误:Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.c ...
- shell中exec命令
1.find中的-exec参数 在当前目录下(包含子目录),查找所有txt文件并找出含有字符串"bin"的行 find ./ -name "*.txt" -ex ...