最近在修改项目的一个需求变更时,无意间发现了以前的一个问题,
这里拿出来讨论,可能在其他项目中没有碰到这样的需求或者无意中规避了这个问题
也或许已经有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”我用过了,但是这个办法有点狠,不太适合

公眾號網頁更新緩存,這玩意兒,說簡單也簡單,說複雜也夠你喝一壺的。你辛辛苦苦更新了公眾號文章,結果用戶打開還是老版本,這滋味,誰受得了?這篇文章,咱就來扒一扒這背後的彎彎繞繞,以及如何優雅地解決這個問題。讀完之後,你就能輕鬆應對各種緩存難題,讓你的用戶始終體驗到最新鮮的內容。先說點基礎的。網頁緩存,說白了就是瀏覽器或者服務器為了提高訪問速度,把一些靜態資源(比如圖片、CSS、JS)或者頁面內容存儲起來。下次訪問時,直接從緩存裡取,不用再重新下載,速度自然快。但這玩意兒,也是個雙刃劍。新版本上線,

本文討論了使用HTML5表單驗證屬性,例如必需的,圖案,最小,最大和長度限制,以直接在瀏覽器中驗證用戶輸入。

本文展示了使用CSS為網頁中添加有效的PNG邊框。 它認為,與JavaScript或庫相比,CSS提供了出色的性能,詳細介紹瞭如何調整邊界寬度,樣式和顏色以獲得微妙或突出的效果

本文討論了html&lt; datalist&gt;元素,通過提供自動完整建議,改善用戶體驗並減少錯誤來增強表格。Character計數:159

本文討論了HTML&lt; meter&gt;元素,用於在一個範圍內顯示標量或分數值及其在Web開發中的常見應用。它區分了&lt; meter&gt;從&lt; progress&gt;和前

本文解釋了HTML5&lt; time&gt;語義日期/時間表示的元素。 它強調了DateTime屬性對機器可讀性(ISO 8601格式)的重要性,並在人類可讀文本旁邊,增強Accessibilit

本文討論了HTML&lt; Progress&gt;元素,其目的,樣式和與&lt; meter&gt;元素。主要重點是使用&lt; progress&gt;為了完成任務和LT;儀表&gt;對於stati


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

禪工作室 13.0.1
強大的PHP整合開發環境