有没有办法使用Flexbox在不同的行上获得相同的列宽?
我希望具有相同的宽度cell--id(宽度必须具有最大的宽度cell--id).
例:
<div class="container">
<div class="row">
<div class="cell cell--id">1</div>
<div class="cell">Test</div>
</div>
<div class="row">
<div class="cell cell--id">2222</div>
<div class="cell">Test</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
<style>
.row { display: flex }
</style>
Run Code Online (Sandbox Code Playgroud)
你需要思考:
在你的情况下,你需要给 .row 一个宽度,并使 flexbox 将单元格均匀地分割在行上:
.row { display: flex; width: 300px }
.cell { flex: 1 } /* each cell width will be: available space divided by the number of cells */
Run Code Online (Sandbox Code Playgroud)
好的,这是 POC:
.row { display: flex; width: 300px }
.cell { flex: 1 } /* each cell width will be: available space divided by the number of cells */
Run Code Online (Sandbox Code Playgroud)
.row { display: flex; width: 500px }
.cell { flex: 1 }Run Code Online (Sandbox Code Playgroud)
您基本上是在描述表格,因此您可能应该使用表格布局,例如
.row { display: table-row }
.cell { display: table-cell }Run Code Online (Sandbox Code Playgroud)
<div class="container">
<div class="row">
<div class="cell cell--id">1</div>
<div class="cell">Test</div>
</div>
<div class="row">
<div class="cell cell--id">2222</div>
<div class="cell">Test</div>
</div>
</div>Run Code Online (Sandbox Code Playgroud)
如果你对 flexbox 死心塌地,我会看到两个选项:
但实际上,我认为您想要表格布局。
| 归档时间: |
|
| 查看次数: |
10060 次 |
| 最近记录: |