【发布时间】:2023-04-03 18:17:01
【问题描述】:
当有 3 个项目/div/元素时,如何使中间 div 自动调整为 100% 宽度?
喜欢
<div style="width:500px; height:50px;">
<div style="float:left; width:50px; height:50px; background-color:red;">
a
</div>
<div style="float:right; width:50px; height:50px; background-color:red;">
b
</div>
<div style="width:auto; height:60px; background-color:blue;">
middle
</div>
<div style="clear:both;"></div>
</div>
我不应该对中间 div 使用固定宽度,因为父 div 宽度 500px 将是响应宽度,在更改浏览器大小时进行调整。
我也试过了
<div style="text-align:center;"> THIS WILL BE DYNAMIC WIDTH
<div style="display:inline-block; width:100px;">
First Div
<div style="display:inline-block; width:WHAT SHOULD I WRITE HERE?;">
Middle Div
</div>
<div style="display:inline-block; width:100px;">
Right Div
</div>
</div>
【问题讨论】: