本文发布于:2009-03-27,最后更新于:2019-04-20,如果内容失效请留言告知。
overflow:hidden 自动隐藏超出的字符,图片,防止撑出层和表格的范围
不过你真的理解了这个标签吗?
主要是这个范围 一般我们只考虑了横向的范围,就是定义width 但是没考虑纵向的范围,没定义height 于是不管怎么搞 就是不隐藏,自动换行,后来在调整上下间距的时候,突然想到没定义height 字符所以会跑到换行 赶紧定义height ok了 显示完美了
下边是div实现两列显示没加overflow:hidden时的代码,在ie中查看效果是正常的,但在firefox中右侧的背景和边框会扩展到左侧.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> < 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中都能正常显示了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> < 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 > |
怎么看不到代码?