关于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可以隐藏超过容器本身的内容: 但是,小编在以往的使用中,发现了一个问题,只要父级容 ...
随机推荐
- js 判断是否选中
js的方法 window.onload = function(){ var oDiv = document.getElementById('div1'); alert(oDiv.checked) } ...
- Linux命令(十三) 建立目录 mkdir 删除目录 rmdir
一.建立目录 mkdir 命令简介 mkdir 命令用于创建指定的目录.创建目录时当前用户对需要操作的目录有读取权限.如果目录已经存在,会提示报错并推出. mkdir 可以创建多级目录. 常用参数说明 ...
- Oracle 最新版本变化 转帖
版本更迭 http://www.sohu.com/a/163264045_505827 Oracle Database的下一个版本将是 Oracle 18. 目的 为了更快的.通过每年的版本发布将新特 ...
- Rust 阴阳谜题,及纯基于代码的分析与化简
Rust 阴阳谜题,及纯基于代码的分析与化简 雾雨魔法店专栏 https://zhuanlan.zhihu.com/marisa 来源 https://zhuanlan.zhihu.com/p/522 ...
- 【刷题】LOJ 6009 「网络流 24 题」软件补丁
题目描述 某公司发现其研制的一个软件中有 \(n\) 个错误,随即为该软件发放了一批共 \(m\) 个补丁程序.每一个补丁程序都有其特定的适用环境,某个补丁只有在软件中包含某些错误而同时又不包含另一些 ...
- 基于Docker持续交付平台建设的实践
导读:中国五矿和阿里巴巴联手打造的钢铁服务专业平台五阿哥,通过集结阿里巴巴在大数据.电商平台和互联网产品技术上的优势,为终端用户带来一站式采购体验.本文是五阿哥运维技术团队针对Docker容器技术在如 ...
- Spring点滴十:Spring自动装配(Autowire)
在基于XML配置元数据,在bean的配置信息中我们可以使用<constructor-arg/>和<property/>属性来实现Spring的依赖注入.Spring 容器也可以 ...
- CRM 常用SQL 脚本
1. 查询角色.用户 SELECT DISTINCT DomainName, u.FullName , u.FirstName, u.InternalEM ...
- 莫比乌斯反演学习笔记+[POI2007]Zap(洛谷P3455,BZOJ1101)
先看一道例题:[POI2007]Zap BZOJ 洛谷 题目大意:$T$ 组数据,求 $\sum^n_{i=1}\sum^m_{j=1}[gcd(i,j)=k]$ $1\leq T\leq 50000 ...
- 【bzoj3091】 城市旅行
http://www.lydsy.com/JudgeOnline/problem.php?id=3091 (题目链接) 题意 给出一棵无根树,维护四个操作.link,cut,路径加法,路径期望查询. ...