文本框设置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”我用过了,但是这个办法有点狠,不太适合

Outils d'IA chauds

Undresser.AI Undress
Application basée sur l'IA pour créer des photos de nu réalistes

AI Clothes Remover
Outil d'IA en ligne pour supprimer les vêtements des photos.

Undress AI Tool
Images de déshabillage gratuites

Clothoff.io
Dissolvant de vêtements AI

AI Hentai Generator
Générez AI Hentai gratuitement.

Article chaud

Outils chauds

Bloc-notes++7.3.1
Éditeur de code facile à utiliser et gratuit

SublimeText3 version chinoise
Version chinoise, très simple à utiliser

Envoyer Studio 13.0.1
Puissant environnement de développement intégré PHP

Dreamweaver CS6
Outils de développement Web visuel

SublimeText3 version Mac
Logiciel d'édition de code au niveau de Dieu (SublimeText3)

Sujets chauds



L'article traite du HTML & lt; Datalist & GT; élément, qui améliore les formulaires en fournissant des suggestions de saisie semi-automatique, en améliorant l'expérience utilisateur et en réduisant les erreurs. COMMANDE COMPRES: 159

L'article traite du HTML & lt; Progress & GT; élément, son but, son style et ses différences par rapport au & lt; mètre & gt; élément. L'objectif principal est de l'utiliser & lt; Progress & gt; pour l'achèvement des tâches et & lt; mètre & gt; pour stati

L'article traite du HTML & lt; mètre & gt; élément, utilisé pour afficher des valeurs scalaires ou fractionnaires dans une plage, et ses applications courantes dans le développement Web. Il différencie & lt; mètre & gt; De & lt; Progress & gt; et ex

L'article traite du & lt; iframe & gt; L'objectif de Tag dans l'intégration du contenu externe dans les pages Web, ses utilisations courantes, ses risques de sécurité et ses alternatives telles que les balises d'objet et les API.

L'article traite de la balise Meta de la fenêtre, essentielle pour la conception Web réactive sur les appareils mobiles. Il explique comment une utilisation appropriée garantit une mise à l'échelle optimale du contenu et une interaction utilisateur, tandis que la mauvaise utilisation peut entraîner des problèmes de conception et d'accessibilité.

L'article discute de l'utilisation des attributs de validation de formulaire HTML5 comme les limites requises, motifs, min, max et longueurs pour valider la saisie de l'utilisateur directement dans le navigateur.

L'article examine les meilleures pratiques pour assurer la compatibilité des navigateurs de HTML5, en se concentrant sur la détection des fonctionnalités, l'amélioration progressive et les méthodes de test.

Cet article explique le html5 & lt; time & gt; élément de représentation sémantique de date / heure. Il souligne l'importance de l'attribut DateTime pour la lisibilité à la machine (format ISO 8601) à côté du texte lisible par l'homme, stimulant AccessIbilit
