修复 td 的宽度
我在 td 中有一个 div 。 div 中内容的宽度是可变的。当我单击 div 时,我将 div 的位置属性从静态更改为绝对。当我更改 td 中 div 的位置属性时,td 会失去其宽度。
请参阅 jsfiddle 获取示例。
当div从静态定位变为绝对定位时,我不希望td调整大小。如何?
<代码>
I've got a div in a td. The width of the content in the div is variable. When I click on the div, I change the div's position attribute from static to absolute. The td loses its width when I change the position attribute of the div within it.
See this jsfiddle for an illustration.
When the div changes from static to absolute positioning, I don't want the td to resize. How?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
td 正在调整大小,因为创建 td 宽度的 div 正在脱离自然文档流。此时 td 认为自己与 div 没有关系。
如果您希望 td 保持该大小,则需要根据 div 的宽度设置 td 的宽度。
更新
这是一种可以快速实现目标的方法:http:// jsfiddle.net/2A2rR/3/
(虽然并不完美,但你已经明白了大概的意思)
The td is resizing because the div, which is creating the width of the td, is taking out of the natural document flow. The td considers itself as having no relation to the div at this point.
You'll need to set the width of the td in accordance with the width of the div if you want it to retain that size.
UPDATE
Here's one way you can quite quickly acheive what you're after: http://jsfiddle.net/2A2rR/3/
(it's not perfect but you get the general idea)