CSS make textbox fill all available width

2019-04-04 07:42发布

I have the following "line" in my web page

<div style="width:100%">
"Some Text" <DropDown> "Some more text" <TextBox> <Button> <Button>
</div>

The DropDown control I don't really have control over the width, as it sizes to fit whatever the longest option value is. The Buttons are fixed width. How can I get the TextBox to fill all available remaining width?

I tried putting it in a table but run into the same problem, ie how do I make all other columns as small as possible to fit their content and then the TextBox column fill remaining width?

Hacky solutions are fine if necessary, I've long ago given up any pretence of even caring about CSS standards when it's so difficult to do the simplest thing.

Edit: to clarify, by TextBox I mean <input type="text"/>

7条回答
何必那么认真
2楼-- · 2019-04-04 08:12

Here is what worked for me. Note that in some cases I had to use &nbsp; between items otherwise it fell to the next line.

.flexContainer {
    display: flex;
    width:100%;
}
input {
    width: 100%;
}
<div class="flexContainer">
<span>text:&nbsp;</span> <input/> &nbsp; <label>text</label>
</div>

查看更多
登录 后发表回答