<!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;的一个诡异问题的更多相关文章

  1. 移动端浏览器body的overflow:hidden并没有什么作用

    今天突然遇到一个问题,使用li模拟select,但是碰到一个很尴尬的问题,给body加了overflow:hidden,但是body并没有禁止滚动条,滚动条依旧顺滑. <!DOCTYPE htm ...

  2. 特别的表格(overflow:hidden的一个小应用)

    做多个li,对各个边的边框有不同的要求,三层盒子,第一层盒子放li,设置右边和下边的虚线边框,浮动,第二层盒子ul设置宽度使li排列,第三层盒子最大的盒子,使用overflow:hidden,宽度高度 ...

  3. overflow:hidden的另一层含义

    overflow:hidden这个CSS样式是大家常用到的CSS样式,但是大多数人对这个样式的理解仅仅局限于隐藏溢出,而对于清除浮动这个含义不是 很了解.一提到清除浮动,我们就会想到另外一个CSS样式 ...

  4. CSS 的overflow:hidden 属性详细解释

    overflow:hidden这个CSS样式是大家常用到的CSS样式,但是大多数人对这个样式的理解仅仅局限于隐藏溢出, 而对于清除浮动这个含义不是很了解.一提到清除浮动,我们就会想到另外一个CSS样式 ...

  5. 解决 border-radius 元素在应用了 transform 的子元素 时overflow:hidden 失效的问题

    受大家启迪,于是最近深入研究了一下Css3中的一些属性.之中也是碰到了个不为我知的问题,在这里特此总结并与大家分享. 问题重现:在父元素上应用了 border-radius 的圆角属性.加上  ove ...

  6. td内容自动换行 ,td超过宽度显示点点点… , td 使用 overflow:hidden 无效,英文 数字 不换行 撑破div容器

    我们可以先给表格 table上 固定一个宽度 不让表格撑破 width: 747px; table-layout:fixed; 然后我们在td上加上如下样式 style="width:100 ...

  7. overflow:hidden清除浮动原理解析及清除浮动常用方法总结

    最近在看<CSS Mastery>这本书,里面有用overflow:hidden来清理浮动的方法.但是一直想不明白为什么能够实现清除浮动,查阅了网络上的解释,下面来总结一下. 一.首先来想 ...

  8. border-radius导致overflow:hidden失效问题。

    如果一个父元素设置了overflow:hidden属于的同时还设置了border-radius属性,那么如果想隐藏超出的子元素,四个圆角处会出现超出圆角依然显示的bug: 一种方法是运用-webkit ...

  9. 关于css中overflow:hidden的使用

    overflow:hidden有两个用处经常用到: 1.通过设定自身的高度,加上overflow:hidden可以隐藏超过容器本身的内容:     但是,小编在以往的使用中,发现了一个问题,只要父级容 ...

随机推荐

  1. TCP/IP 之 大明王朝邮差 (转)

    原创: 刘欣 码农翻身 2016-05-12 前言: 本文主要想说一下TCP的知识, 比喻有不恰当之处,敬请包涵. 大明王朝天启四年, 清晨. 天色刚蒙蒙亮,我就赶着装满货物的马车来到了南城门, 这里 ...

  2. Linux命令(二十) 显示系统内存状态 free

    一.命令简介 free 命令会显示内存的使用情况,包括实体内存,虚拟的交换文件内存.共享内存区段,以及系统核心使用的缓冲区等. 二.参数说明 -b 以Byte为单位显示内存使用情况 -K 以KB为单位 ...

  3. Docker(九)-Docker创建Selenium容器

    SeleniumHQ官方项目:https://github.com/seleniumHQ/docker-selenium 项目目前快速迭代中. Selenium 这里主要针对的是 Selenium G ...

  4. aop 例外通知就是记录业务方法出现错误 并保存到日志里面的功能

    aop 例外通知就是记录业务方法出现错误 并保存到日志里面的功能

  5. BZOJ4078 WF2014Metal Processing Plant(二分答案+2-SAT)

    题面甚至没给范围,由数据可得n<=200.容易想到二分答案,暴力枚举某集合的价值,2-SATcheck一下即可.这样是O(n4logn)的. 2-SAT复杂度已经是下界,考虑如何优化枚举.稍微改 ...

  6. BZOJ5418 NOI2018屠龙勇士(excrt)

    显然multiset求出每次用哪把剑.注意到除了p=1的情况,其他数据都保证了ai<pi,于是先特判一下p=1.比较坑的是还可能存在ai=pi,稍微考虑一下. 剩下的部分即解bix≡ai(mod ...

  7. HGOI 20181030晚 题解

    Problem:给出全班人的个数总分和小明的分数(满分100分),求小明最低排名和最高排名 sol:假设小明的排名为k,总分为sum,小明的分数是r, 贪心求解, 最坏情况下,小明前面的比小明高一分( ...

  8. 消除JQuery Mobile 列表样式右侧箭头

    有时候我们看到JQM上面有一些呈现跟我们要的很像如下面这个Listview效果   程序代码如下: view sourceprint? 1.<ul data-role="listvie ...

  9. centos7搭建ELK Cluster集群日志分析平台

    应用场景:ELK实际上是三个工具的集合,ElasticSearch + Logstash + Kibana,这三个工具组合形成了一套实用.易用的监控架构, 很多公司利用它来搭建可视化的海量日志分析平台 ...

  10. LSTM介绍

    转自:https://blog.csdn.net/gzj_1101/article/details/79376798 LSTM网络 long short term memory,即我们所称呼的LSTM ...