gpt4 book ai didi

css - float div 中输入元素的填充宽度

转载 作者:行者123 更新时间:2023-11-28 18:28:04 24 4
gpt4 key购买 nike

我正在尝试使用 float 在容器中组织宽度为 40% - 30% - 30% 的 div 的水平布局。

在每个 div 中,我想插入纯文本,然后是 输入 字段,该字段填充其 div 的水平其余部分。

作为问题的简化重现,只需在 CSS 上添加:

.r {background-color: pink;}
.g {background-color: lightgreen;}
.b {background-color: lightblue;}
.w40 {width: 40%;}
.w30 {width: 30%;}
.w100 {width: 100%;}
.fl {float: left;}
.fr {float: right;}
.cb {clear: both;}

在 HTML 上:

<div class="r w40 fl">
<div class="g fl">Aaaaaa:</div>
<input class="b" value="Bbbbbb" />
</div>
<div class="r w30 fl">
<div class="g fl">Cccccc:</div>
<div class="b">Dddddd</div>
</div>
<div class="r w30 fl">
<div class="g fl">Eeeeee:</div>
<div class="b">Ffffff</div>
</div>

如何让 BbbbbbDddddddFfffff 一样占据其 div 右侧的所有空间?

这是我期待的: Goal

最佳答案

From this answer:我只是将输入包装在一个带有 overflow: hidden 样式的 div 中。

CSS:

.r {background-color: pink;}
.g {background-color: lightgreen;}
.b {background-color: lightblue;}
.w40 {width: 40%;}
.w30 {width: 30%;}
.w100 {width: 100%;}
.fl {float: left;}
.filler {overflow: hidden; padding-right: 4px;}

HTML:

<div class="r w40 fl">
<div class="g fl">Aaaaaa:</div>
<div class="filler"><input class="b w100" value="Bbbbbb" /></div>
</div>
<div class="r w30 fl">
<div class="g fl">Cccccc:</div>
<div class="b">Dddddd</div>
</div>
<div class="r w30 fl">
<div class="g fl">Eeeeee:</div>
<div class="b">Ffffff</div>
</div>

This is it. The perfect result!

关于css - float div 中输入元素的填充宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15146801/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com