100%宽度的textarea会忽略IE7中父元素的宽度 [英] 100% width textarea ignores parent element's width in IE7

查看:89
本文介绍了100%宽度的textarea会忽略IE7中父元素的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在table中有以下textarea:

<table width="300"><tr><td>

<textarea style="width:100%">
longstringlongstringlongstringlongstringlongstringlongstringlongstringlongstringlongstringlongstringlongstringlongstringlongstring
</textarea>

</td></tr></table>

在textarea中使用长字符串,textarea可以扩展以容纳它在IE7中的一行中,但在其他浏览器中保留其300px宽度.

With a long string in the textarea, the textarea stretches out to accommodate it in one line in IE7, but retains its 300px width in other browsers.

关于如何在IE中解决此问题的任何想法?

Any ideas as to how to fix this in IE?

推荐答案

将宽度应用于td,而不是table.

Apply the width to the td, not the table.

@Emmett-可以通过CSS轻松地应用宽度.

@Emmett - the width could just as easily be applied via CSS.

td {
    width: 300px;
}

产生所需的结果.或者,如果您使用的是jQuery,则可以通过脚本添加宽度:

produces the desired result. Or, if you're using jQuery, you could add the width through script:

$('textarea[width=100%]').parent('td').css('width', '300px');

要点是,如果开发限制使您无法直接将其应用于表格单元格,则有多种方法可以将其应用于表格单元格.

Point being, there's more than one way to apply a width to a table cell, if development constraints prevent you from applying it directly.

这篇关于100%宽度的textarea会忽略IE7中父元素的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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