[css] table-layout:fixed 属性的解说,IE、Firefox效果对比详解

table-layout:fixed 属性的解说

若是想要一个table固定大小,里面的文字强制换行(尤为是在一长串英文文本,而且中间无空格分隔的情 况下),以达到使过长的文字不撑破表格的目的,通常是使用样式:table-layout:fixed。可是在Firefox下面,会有一些问题,参考 Gmail的一些作法,作了几个测试,得出一种解决办法。
例1:(IE浏览器)普通的状况
CODE:
<table border=1 width=80><tr><td>abcdefghigklmnopqrstuvwxyz 1234567890</td></tr></table>

效果:
能够看到width=80并无起做用,表格被字符撑开了。

例2:(IE浏览器)使用样式table-layout:fixed
CODE:
<style>.tbl {table-layout:fixed}</style><table class=tbl border=1 width=80><tr><td>abcdefghigklmnopqrstuvwxyz 1234567890</td></tr></table>

效果:
width=80起做用了,可是表格换行了。
 
 
例3:(IE浏览器)使用样式table-layout:fixed与nowrap
CODE:
<style>.tbl {table-layout:fixed}</style><table class=tbl border=1 width=80><tr><td nowrap>abcdefghigklmnopqrstuvwxyz 1234567890</td></tr></table>

效果: width=80起做用了,换行也被干掉了。
 
例4:(IE浏览器)在使用数值固定td大小状况下使用样式table-layout:fixed与nowrap
CODE:
<style>.tbl {table-layout:fixed}</style><table class=tbl border=1 width=80><tr><td width=20 nowrap>abcdefghigklmnopqrstuvwxyz 1234567890</td><td nowrap>abcdefghigklmnopqrstuvwxyz 1234567890</td></tr></table>

效果: 不幸发生了,第一个td的nowrap不起做用了
 
例5:(IE浏览器)在使用百分比固定td大小状况下使用样式table-layout:fixed与nowrap
CODE:
<style>.tbl {table-layout:fixed}</style><table class=tbl border=1 width=80><tr><td width=25% nowrap>abcdefghigklmnopqrstuvwxyz 1234567890</td><td nowrap>abcdefghigklmnopqrstuvwxyz 1234567890</td></tr></table>

效果: 改为百分比,终于搞定了
 
例6:(Firefox浏览器)在使用百分比固定td大小状况下使用样式table-layout:fixed与nowrap效果: 把例5放到firefox下面,又ft了
 
例7:(Firefox浏览器)在使用百分比固定td大小状况下使用样式table-layout:fixed与nowrap,而且使用div
CODE:
<style>.tbl {table-layout:fixed}.td {overflow:hidden;}</style><table class=tbl border=1 width=80><tr><td width=25% class=td nowrap><div>abcdefghigklmnopqrstuvwxyz 1234567890</div></td><td class=td nowrap><div>abcdefghigklmnopqrstuvwxyz 1234567890</div></td></tr></table>

效果: 天下终于太平了
 
例8:(Firefox浏览器)在使用数值固定td大小状况下使用样式table-layout:fixed与nowrap,而且使用div
CODE:
<style>.tbl {table-layout:fixed}.td {overflow:hidden;}</style>


CODE:
<table class=tbl border=1 width=80><tr><td width=20 class=td nowrap><div>abcdefghigklmnopqrstuvwxyz 1234567890</div></td><td class=td nowrap><div>abcdefghigklmnopqrstuvwxyz 1234567890</div></td></tr></table>

效果: nowrap又不起做用了
 
 
最终,例7是一个在IE和Firefox均可以完美解决页面强制换行问题的解决方案。
相关文章
相关标签/搜索