Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make input text field full width inside table cell

Tags:

html

css

http://jsfiddle.net/p1my39fh/

table {
    width: 550px;
    border-collapse:collapse;
    margin: auto;
    background-color: #A4A4A4;
    border: 2px solid black;
    padding: 0;
}
table td {
    position: relative;
    text-align: center;
    border: 2px solid green;
    padding: 0;
    margin: 0;
}
<table>
    <tr>
        <td><input type="text" size="30"/></td>
        <td>Test Information</td>
    </tr>
</table>

How can I remove the space around the <input>?

How can I make both <td>s to be the same width?

like image 520
DerekConlon Avatar asked Jun 11 '15 16:06

DerekConlon


People also ask

How do you change the input field width?

The width attribute specifies the width of the <input> element. Note: The width attribute is used only with <input type="image"> . Tip: Always specify both the height and width attributes for images. If height and width are set, the space required for the image is reserved when the page is loaded.

How do you increase cell width in a table?

To adjust column width automatically, click AutoFit Contents. To adjust table width automatically, click AutoFit Window.

How do I resize a text field?

Resize a text box Select the text box. Select one of the handles and drag until the text box is the size you want.


2 Answers

To make both <td>s to have same width, you could set:

table {
    width: 550px;
    table-layout: fixed;
}

To have the <input> to fill the entire width of the <td>, you could set:

input {
    width: 100%;
    box-sizing: border-box;
}

Updated demo:

table {
    width: 550px;
    border-collapse:collapse;
    margin: auto;
    background-color: #A4A4A4;
    border: 2px solid black;
    table-layout: fixed;
}
td {
    text-align: center;
    border: 2px solid green;
}
td input {
    width: 100%;
    box-sizing: border-box;
}
<table>
    <tr>
        <td><input type="text" size="30"/></td>
        <td>Test Information</td>
    </tr>
</table>
like image 64
Stickers Avatar answered Sep 18 '22 21:09

Stickers


The answer was:

why don't you set the width of td to 275px, since you have a fixed width? – jp-jee Jun 11 at 16:43

That comment.

Setting the width to a fixed length worked for me.

like image 32
DerekConlon Avatar answered Sep 20 '22 21:09

DerekConlon