overflow:hidden控制div溢出问题

11,477次阅读
一条评论

共计 1256 个字符,预计需要花费 4 分钟才能阅读完成。

提醒:本文最后更新于2019-04-20 14:57,文中所关联的信息可能已发生改变,请知悉!

overflow:hidden 自动隐藏超出的字符,图片,防止撑出层和表格的范围

不过你真的理解了这个标签吗?

主要是这个范围 一般我们只考虑了横向的范围,就是定义width 但是没考虑纵向的范围,没定义height 于是不管怎么搞 就是不隐藏,自动换行,后来在调整上下间距的时候,突然想到没定义height 字符所以会跑到换行 赶紧定义height ok了 显示完美了

下边是div实现两列显示没加overflow:hidden时的代码,在ie中查看效果是正常的,但在firefox中右侧的背景和边框会扩展到左侧.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>firefox中div两列</title>
<style type="text/css">
.w {width:400px;}
.d1 {height:50px;float:left;}
.d2 {height:50px;background:#F9EDFA;border:2px dotted #A63DAD;}
</style>
</head>
<body>
<div class="w">
<div class="d1">左侧</div><div class="d2">右侧</div>
</div>
</body>
</html>

下边是修正后的代码,在firefox和ie中都能正常显示了

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>firefox中div两列</title>
<style type="text/css">
.w {width:400px;}
.d1 {height:50px;float:left;}
.d2 {height:50px;background:#F9EDFA;border:2px dotted #A63DAD;overflow:hidden}
</style>
</head>
<body>
<div class="w">
<div class="d1">左侧</div><div class="d2">右侧</div>
</div>
</body>
</html>

正文完
 0
任侠
版权声明:本站原创文章,由 任侠 于2009-03-27发表,共计1256字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(一条评论)
验证码
不知所谓 评论达人 LV.1
2019-04-16 15:41:44 回复
Google Chrome 73.0.3683.103 Google Chrome 73.0.3683.103 Windows 10 x64 Edition Windows 10 x64 Edition

怎么看不到代码?

 Windows  Chrome  中国湖北省武汉市电信