简体   繁体   English

使输入占用所有剩余空间

[英]Make an input take up all the remaining space

My problem is similar to this question , but different. 我的问题类似于此问题 ,但有所不同。

I have a table cell of an unknown width. 我有一个宽度未知的表格单元。 This cell contains an input and a span . 该单元格包含一个input和一个span The span should be as wide as its contents needs and the input should take all the remaining space . span根据其内容的需要变宽, input占据所有剩余空间

I've created a trivial plunk for this seemingly trivial question. 我为这个看似微不足道的问题创建了一个琐碎的小插曲 The random text should be on the very right and the input should grow or shrink as needed to fill the yellow td . 随机文本应在最右边,输入应根据需要增大或缩小以填充黄色td

Try splitting the yellow <td> into its own table (or other elements using display: table-cell , etc). 尝试将黄色的<td>拆分到自己的表中(或使用display: table-cell等其他元素)。

Set the width of the cell containing the input to 100%, and set the max-width of the table to 100%. 将包含输入的单元格的宽度设置为100%,并将表的最大宽度设置为100%。

That will cause the table inside the cell to re-flow when the text changes. 当文本更改时,这将导致单元格内的表重新排序。

Basic demo: http://plnkr.co/edit/ao4at9RHg8VgRrgtmTqu?p=preview 基本演示: http : //plnkr.co/edit/ao4at9RHg8VgRrgtmTqu?p=preview

This can be achieved with Flexbox. 这可以通过Flexbox实现。

HTML: HTML:

<td class="foo">
    <input class="foo__input">
    <span>dsflkwej</span>                
</td>

CSS: CSS:

.foo {
    display: flex
}
.foo__input {
    flex-grow: 1
}

Live demo: http://jsfiddle.net/simevidas/MhR77/ 现场演示: http //jsfiddle.net/simevidas/MhR77/

(Use Autoprefixer to add vendor prefixes for Flexbox properties.) (使用Autoprefixer为Flexbox属性添加供应商前缀。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM