# Make input box just fill a table cell

**URL:** <https://www.phphelp.com/t/make-input-box-just-fill-a-table-cell/35217>\
**Category:** HTML & CSS\
**Created:** [January 13, 2023, 12:24am UTC](https://www.phphelp.com/t/make-input-box-just-fill-a-table-cell/35217 "2023-01-13T00:24:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![conexor](https://www.phphelp.com/user_avatar/www.phphelp.com/conexor/32/4155_2.png) [@conexor](https://www.phphelp.com/u/conexor)\
**Post date:** [January 13, 2023, 12:24am UTC](https://www.phphelp.com/t/make-input-box-just-fill-a-table-cell/35217/1 "2023-01-13T00:24:00Z")

</div>

I can put an HTML input box inside a table cell like this

```auto
<TD COLWIDTH='50' ><INPUT type='text' size=' **some number**' value='123456'></TD>

```

BUT  
if ‘ **some number** ’ is such that the input box is too large, it pushes the cell wider than the value specified in the COLWIDTH

**Is there a way to specify that the input box should just fill the cell?**

What I mean is that If the input box wants to be smaller than COLWIDTH then it should expand to fill the cell width and if the input box wants to be bigger than the cell then it would just shrink the size of the cell.

---

<div class="post-metadata">

**Author:** ![ErnieAlex](https://www.phphelp.com/letter_avatar_proxy/v4/letter/e/bc8723/32.png) [@ErnieAlex](https://www.phphelp.com/u/ErnieAlex)\
**Post date:** [January 13, 2023, 5:37am UTC](https://www.phphelp.com/t/make-input-box-just-fill-a-table-cell/35217/2 "2023-01-13T05:37:32Z")

</div>

PS: NOBODY uses width’s in HTML anymore! No colwidth’s are ever used. They are done in CSS !!!

---

<div class="post-metadata">

**Author:** ![conexor](https://www.phphelp.com/user_avatar/www.phphelp.com/conexor/32/4155_2.png) [@conexor](https://www.phphelp.com/u/conexor)\
**Post date:** [January 13, 2023, 6:30am UTC](https://www.phphelp.com/t/make-input-box-just-fill-a-table-cell/35217/3 "2023-01-13T06:30:14Z")

</div>

Good o. And so can you send the style sheet code to show how to make the input box just fill the cell and not push it wider.

---

<div class="post-metadata">

**Author:** ![ErnieAlex](https://www.phphelp.com/letter_avatar_proxy/v4/letter/e/bc8723/32.png) [@ErnieAlex](https://www.phphelp.com/u/ErnieAlex)\
**Post date:** [January 13, 2023, 4:10pm UTC](https://www.phphelp.com/t/make-input-box-just-fill-a-table-cell/35217/4 "2023-01-13T16:10:54Z")

</div>

> [@conexor](#):
>
> `<td style='width: 50px;' ><input type='text' value='123456' style='width: 45px;'></TD>`

Not sure if that is what you wanted. But, you just put in the values you want to use.  
Sometimes it is handy or perhaps more useful to use max-width: 50px; instead of just width.

---

<div class="post-metadata">

**Author:** ![WildFire2000](https://www.phphelp.com/letter_avatar_proxy/v4/letter/w/7bcc69/32.png) [@WildFire2000](https://www.phphelp.com/u/WildFire2000)\
**Post date:** [January 20, 2023, 6:05am UTC](https://www.phphelp.com/t/make-input-box-just-fill-a-table-cell/35217/6 "2023-01-20T06:05:21Z")

</div>

You can use styles as well using the following codes in your HTML  
Add the following to your HTML after the title

```
<link rel="stylesheet" type="text/css" href="styles.css">

```

add this to the body

```
<td class='width1' ><input type='text' value='123456' class='width2'></TD>        

```

* * *

styles.css

.width1{  
width: 50px;  
}

.width2{  
background-color: #dadada;  
width: 45px;  
}

Hope this helps.
