<!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. K8S 使用简单的NFS 作为 持久存储的 StorageClass 的简单测试.

    Study From https://jimmysong.io/kubernetes-handbook/practice/using-nfs-for-persistent-storage.html 1 ...

  2. PHP仿LED点阵,读取字库文字,并转化为二进制输出

    <?php $xml=simplexml_load_file("zimu.xml");//导入XML文件,从XML文件里知道需要提取的字体的信息 $font_height=$ ...

  3. 深入解读Quartz的原理

     Quartz是一个大名鼎鼎的Java版开源定时调度器,功能强悍,使用方便.   一.核心概念   Quartz的原理不是很复杂,只要搞明白几个概念,然后知道如何去启动和关闭一个调度程序即可.   1 ...

  4. BZOJ 3171 循环格(费用流)

    题意 一个循环格就是一个矩阵,其中所有元素为箭头,指向相邻四个格子.每个元素有一个坐标(行,列),其中左上角元素坐标为(0,0).给定一个起始位置(r,c),你可以沿着箭头防线在格子间行走.即如果(r ...

  5. 【题解】 [HNOI2015]落忆枫音 (拓扑排序+dp+容斥原理)

    原题戳我 Solution: (部分复制Navi_Aswon博客) 解释博客中的两个小地方: \[\sum_{\left(S是G中y→x的一条路径的点集\right))}\prod_{2≤j≤n,(j ...

  6. 搜索引擎(Solr-搜索详解)

    学习目标 1.掌握SOLR的搜索工作流程: 2.掌握solr搜索的表示语法及查询解析器 3.熟悉solr搜索的JSON格式 API Solr搜索流程介绍 回顾,使用 lucene进行搜索的步骤: So ...

  7. BZOJ 百题纪念!

    一百题辣! 现在NOI知识点中最基础的那部分已经学完了--这几天发现自己会写SA啊树剖啊可持久化Trie啊之类模板题--还挺开心的-- 逛了两天学长博客之后--BZOJ100题辣--也挺开心的-- 现 ...

  8. luogu1328 [NOIp2014]生活大爆炸版石头剪刀布 (模拟)

    #include<bits/stdc++.h> #define pa pair<int,int> #define CLR(a,x) memset(a,x,sizeof(a)) ...

  9. 纯干货!一款APP从设计稿到切图过程全方位揭秘(转)

    @BAT_LCK :我本身是一名GUI设计师,所以我只站在GUI设计师的角度去把APP从项目启动到切片输出的过程写一写,相当于工作流程的介绍吧.公司不同,流程不尽相同,但是终究还是能有些帮助. 依旧声 ...

  10. java基础基础总结----- 随机数(产生四个随机数)

    前言:在开发的时候经常会遇见,一些验证码登录,其实这些东西,很简单.我曾经开发过一个验证码登录的页面,那时用的插件.但是作为一个合格的开发者,要了解其内部的核心知识,有些东西,可以不深入了解,但是要做 ...