TD 内的 DIV 是个坏主意吗? [英] Is a DIV inside a TD a bad idea?

查看:27
本文介绍了TD 内的 DIV 是个坏主意吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎我在某处听到/读到

内的 是一个禁忌.并不是说它不起作用,只是基于它们的显示类型它们并不真正兼容.找不到任何证据来支持我的预感,所以我可能完全错了.

解决方案

td 中使用 div 并不比使用表格进行布局的任何其他方式差.(不过有些人从不使用表格进行布局,而我恰好是其中之一.)

如果您在 td 中使用 div,您将遇到可能难以预测元素大小的情况.div 的默认值是根据其父级确定其宽度,表格单元格的默认值是根据其内容的大小来确定其大小.

div 的大小规则在标准中有很好的定义,但是 td 的大小规则没有那么明确,所以不同的浏览器使用的算法略有不同.

It seems like I heard/read somewhere that a <div> inside of a <td> was a no-no. Not that it won't work, just something about them not being really compatible based on their display type. Can't find any evidence to back up my hunch, so I may be totally wrong.

解决方案

Using a div instide a td is not worse than any other way of using tables for layout. (Some people never use tables for layout though, and I happen to be one of them.)

If you use a div in a td you will however get in a situation where it might be hard to predict how the elements will be sized. The default for a div is to determine its width from its parent, and the default for a table cell is to determine its size depending on the size of its content.

The rules for how a div should be sized is well defined in the standards, but the rules for how a td should be sized is not as well defined, so different browsers use slightly different algorithms.

这篇关于TD 内的 DIV 是个坏主意吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆