搜尋
首頁web前端html教學文本框设置100%宽度,内容过多时所在td的宽度失效_html/css_WEB-ITnose

最近在修改项目的一个需求变更时,无意间发现了以前的一个问题,

这里拿出来讨论,可能在其他项目中没有碰到这样的需求或者无意中规避了这个问题

也或许已经有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”我用过了,但是这个办法有点狠,不太适合

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
為什麼HTML屬性對Web開發很重要?為什麼HTML屬性對Web開發很重要?May 12, 2025 am 12:01 AM

htmlattributesarecrucialinwebdevelopment forcontrollingBehavior,外觀和功能

Alt屬性的目的是什麼?為什麼重要?Alt屬性的目的是什麼?為什麼重要?May 11, 2025 am 12:01 AM

alt屬性是HTML中標籤的重要部分,用於提供圖片的替代文本。 1.當圖片無法加載時,alt屬性中的文本會顯示,提升用戶體驗。 2.屏幕閱讀器使用alt屬性幫助視障用戶理解圖片內容。 3.搜索引擎索引alt屬性中的文本,提高網頁的SEO排名。

HTML,CSS和JavaScript:示例和實際應用HTML,CSS和JavaScript:示例和實際應用May 09, 2025 am 12:01 AM

HTML、CSS和JavaScript在網頁開發中的作用分別是:1.HTML用於構建網頁結構;2.CSS用於美化網頁外觀;3.JavaScript用於實現動態交互。通過標籤、樣式和腳本,這三者共同構築了現代網頁的核心功能。

如何在標籤上設置lang屬性?為什麼這很重要?如何在標籤上設置lang屬性?為什麼這很重要?May 08, 2025 am 12:03 AM

設置標籤的lang屬性是優化網頁可訪問性和SEO的關鍵步驟。 1)在標籤中設置lang屬性,如。 2)在多語言內容中,為不同語言部分設置lang屬性,如。 3)使用符合ISO639-1標準的語言代碼,如"en"、"fr"、"zh"等。正確設置lang屬性可以提高網頁的可訪問性和搜索引擎排名。

HTML屬性的目的是什麼?HTML屬性的目的是什麼?May 07, 2025 am 12:01 AM

htmlattributeseresene forenhancingwebelements'functionalityandAppearance.TheyAdDinformationTodeFineBehavior,外觀和互動,使網站互動,響應式,visalalyAppealing.AttributesLikutesLikeSlikEslikesrc,href,href,href,類,類型,類型,和dissabledtransfransformformformformformformformformformformformformformformforment

您如何在HTML中創建列表?您如何在HTML中創建列表?May 06, 2025 am 12:01 AM

toCreateAlistInHtml,useforforunordedlistsandfororderedlists:1)forunorderedlists,wrapitemsinanduseforeachItem,RenderingeringAsabulletedList.2)fororderedlists,useandfornumberedlists,useandfornumberedlists,casundfornumberedlists,casundfornthetthetthetthetthetthetthetttributefordforderfordforderforderentnumberingsnumberingsnumberingStys。

HTML行動:網站結構的示例HTML行動:網站結構的示例May 05, 2025 am 12:03 AM

HTML用於構建結構清晰的網站。 1)使用標籤如、、定義網站結構。 2)示例展示了博客和電商網站的結構。 3)避免常見錯誤如標籤嵌套不正確。 4)優化性能通過減少HTTP請求和使用語義化標籤。

您如何將圖像插入HTML頁面?您如何將圖像插入HTML頁面?May 04, 2025 am 12:02 AM

toinsertanimageIntoanhtmlpage,usethetagwithsrcandaltattributes.1)usealttextforAcccessibilityandseo.2)instementRcsetForresponSiveImages.3)applylazyloadingWithLoadingWithLoading =“ lazy” tooptimizeperformance.4)tooptimizeperformance.4)

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

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

AI Clothes Remover

AI Clothes Remover

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

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver Mac版

Dreamweaver Mac版

視覺化網頁開發工具

MantisBT

MantisBT

Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

SublimeText3 英文版

SublimeText3 英文版

推薦:為Win版本,支援程式碼提示!