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

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

问题描述

看来我听到/读过某个< div> < td> 是一个禁忌。并不是说它不起作用,只是基于它们的显示类型而不是真正兼容的东西。找不到任何证据来支持我的预感,所以我可能完全错误。 使用 div 显示 td 并不比任何其他使用表格进行布局的方式差。 (有些人从不使用表格进行布局,我恰好是其中之一)。



如果您使用 div td 中,你会遇到一种情况,可能很难预测元素的大小。 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天全站免登陆