Let span fill remaining width?

2020-03-01 03:27发布

I have the following li item:

<li>
  <span style='float:left; background-color:red'>a</span>
  <span style='float:left; background-color:green'>b</span>
</li>

I'd like the span on the right to fill whatever width is remaining in its parent li. Is there a way to do that?

Thanks

标签: css
3条回答
Evening l夕情丶
2楼-- · 2020-03-01 03:36

Looked for the same solution, but found only this which worked great for me:

<li>
  <span style='display: table-cell; background-color:red'>a</span>
  <span style='display: table-cell; width: 100%; background-color:green'>b</span>
</li>

All you need is just using table-cell displaying and set filler span width to 100%. All other solutions I've tried didn't work for me as expected.

查看更多
可以哭但决不认输i
3楼-- · 2020-03-01 04:00

Don't float the second one, and make it display:block.

http://jsfiddle.net/ymAt5/

查看更多
▲ chillily
4楼-- · 2020-03-01 04:03

You don't want to float each of them left, only the first one, and then make the second one display in block mode:

<li>
  <span style='float:left; background-color:red'>a</span>
  <span style="display: block; background-color:green;">b</span>
</li>
查看更多
登录 后发表回答