Domanda

Ho un tovaglia con un campo di input in esso. Il campo di input deve riempire il tablecell ma non raggiungere la sua imbottitura. Quello che ho assomiglia a questo (con Firebug):

Elemento del modulo Raggiungere il riempimento

Voglio che il campo di input venga tenuto all'interno dell'area blu e non raching nel viola.

E: ovviamente leggo tutte le domande qui su questo argomento prima. Ho letto tutto e non ho trovato nessuna risposta che in realtà ha risolto questo.

dovrebbe funzionare in tutti i browser moderni (anche IE7);

Ho fatto un Esempio minimo in diretta con Jsfiddle dove ho provato tutte le soluzioni nelle altre domande Ma non riuscivo a farlo funzionare. a) Esiste una soluzione funzionante per questo? e B) C'è anche una soluzione piacevole e non solitaria per questo?

Perché è un problema in tutti i browser? Penso che questa sia una specifica sbagliata in CSS. Perché se dico "100%", naturalmente, voglio che l'elemento si adattasse "100%" dell'area del contenuto. Qual è il caso d'uso per lasciarlo fluire in paddings e margini?

È stato utile?

Soluzione

Well, here you go..

I'm using the exact same method as this answer.

See: http://jsfiddle.net/AKUsB/

CSS:

.inputContainer {
    background: #fff;
    padding: 3px 3px;
    border: 1px solid #a9a9a9
}
.inputContainer input {
    width: 100%;
    margin: 0; padding: 0; border: 0;
    display: block
}

HTML:

<div class="inputContainer">
    <input type="text" name="company" id="company" value="" class="formInputTextField" style="width: 100%;" />
</div>

Altri suggerimenti

The problem here is with the box model, when you say width: 100% it applies a pixel value based on what's available (which you can see under the "computed styles" option of a web inspector). However, padding is then added on to that width, so a padding of 5px would compute to a total width of 100% + 10px (5 for each side).

To fix this problem, you need to remove your padding, or incorporate it into your width value. For example:

input { width: 100%; padding: 0; }

Or

input { width: 90%; padding: 0 5%; } /* width totals 100% */

Most form elements, by default, inherit some amount of padding; so even if you're not specifically applying padding to the input, it's still on there because the browser defaults it to have padding.

I think you should try to use

box-sizing: border-box
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top