Input text box and width 100%

2019-07-25 11:36发布

I'm writing a simple form for sending some data to a database.

I use it in my own company so I don't need to have a perfect style.

I am using a table for the layout (this is okay in this application).

<table width="500px" style="border:1px solid black; overflow:hidden">
    <tr>
     <td>Born <input type="text" name="nato_pf" /></td>
    </tr>
</table>

I would like to set the width of the input text to 100% (to the end of the line) , but, if I do that, the input text wraps to a new line.

I have found solutions only using div and they are not for me at the moment.

EDIT: Sometimes I have two input (with different sizes) on the same line, so I think I cannot add other td tags.

3条回答
Melony?
2楼-- · 2019-07-25 12:24
<table width="500px" style="border: 1px solid black; verflow: hidden">
    <tr>
        <td style="width: 50px;">
            Born
        </td>
        <td>
            <input type="text" name="nato_pf" style="width: 99%;" />
        </td>
    </tr>
</table>

99% of width because with 100% the textbox goes over the table's border :) and also give a width to the first td ;)

jsFiddle http://jsfiddle.net/2yZmB/

查看更多
我想做一个坏孩纸
3楼-- · 2019-07-25 12:30

http://jsfiddle.net/gmmr7/1

table {
    border:1px solid black;
    width: 200px;
}

.left {
    float: left;
}

.left2 {
    overflow: hidden;
    padding: 0 4px;
}

.left2>input {
    width: 100%
}
<table>
    <tr>
        <td>
            <label class="left">Born</label>
            <div class="left2">
                <input type="text" name="nato_pf" />
            </div>
        </td>
    </tr>
</table>
查看更多
男人必须洒脱
4楼-- · 2019-07-25 12:32

you can define another td element

<table width="500px" style="border:1px solid black; overflow:hidden">
    <tr>
        <td>Born </td><td><input type="text" name="nato_pf" /></td>
    </tr>
</table>

css

input{
    width:99%;

}
查看更多
登录 后发表回答