最近在修改项目的一个需求变更时,无意间发现了以前的一个问题,
这里拿出来讨论,可能在其他项目中没有碰到这样的需求或者无意中规避了这个问题
也或许已经有html&CSS高手把问题解决,都请来分享一下经验:
问题描述如下
因为客户不太懂技术,把上述td的宽度设置了百分比,然后为了好看又把里面的文本框也设置了width:100%,想让他自适应
更改之后变成这样
1 <html> 2 <head> 3 4 </head> 5 <body> 6 <table style="background-color:green;width:100%"> 7 <tr> 8 <th style="width:20%;background-color:red">th1</th> 9 <td style="width:30%;background-color:yellow">10 <input type="text" style="width:100%" maxlength="100" value="">11 </td>12 <th style="width:30%;background-color:red">th2</th>13 <td style="width:20%;background-color:yellow">14 <input type="text" maxlength="100" style="width:100%" value="">15 </td>16 </tr>17 </table>18 <table style="background-color:white;width:100%">19 <tr>20 <th style="width:20%;background-color:red">th1</th>21 <td style="background-color:yellow">22 <input type="text" maxlength="100" style="width:100%" value="">23 </td>24 25 </tr>26 <tr>27 <th style="width:20%;background-color:red">th1</th>28 <td style="background-color:yellow">29 <input type="text" maxlength="100" style="width:100%" value="">30 </td>31 32 </tr>33 <tr>34 <th style="width:20%;background-color:red">th1</th>35 <td style="background-color:yellow">36 <input type="text" maxlength="20" style="width:100%" value="">37 </td>38 39 </tr>40 <tr>41 <th style="width:20%;background-color:red">th1</th>42 <td style="background-color:yellow">43 <input type="text" maxlength="20" style="width:100%" value="">44 </td>45 46 </tr>47 <tr>48 <th style="width:20%;background-color:red">th1</th>49 <td style="background-color:yellow">50 <input type="text" maxlength="20" style="width:100%" value="">51 </td>52 53 </tr>54 </table>55 </body>56 </html>
因为是老代码,这个画面恶心的地方首先是第一行和下面的各行不在一个table里,
图中的这个文本框对应的数据库表对应的字段是一个100位英文内容,如果满位输出的话,画面变成了这样。。。
1 <html> 2 <head> 3 4 </head> 5 <body> 6 <table style="background-color:green;width:100%"> 7 <tr> 8 <th style="width:20%;background-color:red">th1</th> 9 <td style="width:30%;background-color:yellow">10 <input type="text" style="width:100%" maxlength="100" value="0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789">11 </td>12 <th style="width:30%;background-color:red">th2</th>13 <td style="width:20%;background-color:yellow">14 <input type="text" maxlength="100" style="width:100%" value="">15 </td>16 </tr>17 </table>18 <table style="background-color:white;width:100%">19 <tr>20 <th style="width:20%;background-color:red">th1</th>21 <td style="background-color:yellow">22 <input type="text" maxlength="100" style="width:100%" value="">23 </td>24 25 </tr>26 <tr>27 <th style="width:20%;background-color:red">th1</th>28 <td style="background-color:yellow">29 <input type="text" maxlength="100" style="width:100%" value="">30 </td>31 32 </tr>33 <tr>34 <th style="width:20%;background-color:red">th1</th>35 <td style="background-color:yellow">36 <input type="text" maxlength="20" style="width:100%" value="">37 </td>38 39 </tr>40 <tr>41 <th style="width:20%;background-color:red">th1</th>42 <td style="background-color:yellow">43 <input type="text" maxlength="20" style="width:100%" value="">44 </td>45 46 </tr>47 <tr>48 <th style="width:20%;background-color:red">th1</th>49 <td style="background-color:yellow">50 <input type="text" maxlength="20" style="width:100%" value="">51 </td>52 53 </tr>54 </table>55 </body>56 </html>
目测,这个文本框因为有一个maxlength=100,的设置,ie试图在允许的范围下,把内容全部显示,但是这样的话,画面就乱了,
测试环境是:IE 9,IE 8下也存在该问题,在chrome下完美解析,如下图:
所以据此推测是IE在解析INPUT上和chrome内核不太一致,但是现在开发是在IE8上进行,除了设置固定width和使用Js动态加载,有没有别的办法来兼容解决问题。。。
注:style=“table-layout:fixed”我用过了,但是这个办法有点狠,不太适合

本文讨论了HTML&lt; Progress&gt;元素,其目的,样式和与&lt; meter&gt;元素。主要重点是使用&lt; progress&gt;为了完成任务和LT;仪表&gt;对于stati

本文讨论了html&lt; datalist&gt;元素,通过提供自动完整建议,改善用户体验并减少错误来增强表格。Character计数:159

本文讨论了HTML&lt; meter&gt;元素,用于在一个范围内显示标量或分数值及其在Web开发中的常见应用。它区分了&lt; meter&gt;从&lt; progress&gt;和前

本文讨论了视口元标签,这对于移动设备上的响应式Web设计至关重要。它解释了如何正确使用确保最佳的内容缩放和用户交互,而滥用可能会导致设计和可访问性问题。

本文讨论了使用HTML5表单验证属性,例如必需的,图案,最小,最大和长度限制,以直接在浏览器中验证用户输入。

本文解释了HTML5&lt; time&gt;语义日期/时间表示的元素。 它强调了DateTime属性对机器可读性(ISO 8601格式)的重要性,并在人类可读文本旁边,增强Accessibilit

本文讨论了&lt; iframe&gt;将外部内容嵌入网页,其常见用途,安全风险以及诸如对象标签和API等替代方案的目的。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

PhpStorm Mac 版本
最新(2018.2.1 )专业的PHP集成开发工具

WebStorm Mac版
好用的JavaScript开发工具

ZendStudio 13.5.1 Mac
功能强大的PHP集成开发环境

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。