Eri*_*rel 29 css layout flexbox bootstrap-4
在文档和Bootstrap v4 (这里)的问题中,我看不到任何支持计划flex-grow
,例如这样的语法:
<div class="d-flex">
<div class="flex-grow">
I use all the space left
</div>
<div>
I am a small text on the right
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这里是我想要创建的布局示例:
导出按钮始终在右侧,导航按钮占用了所有空间,因此看起来很干净.
是否有可能建立这样的布局?也许不建议?当然,有一些使用CSS的解决方法,但我正在寻找一个干净的解决方案,理想情况下只使用Bootstrap类名来保证一致性.
Mic*_*ker 33
用.col
一个简单的flex-grow: 1;
.它在这里描述https://v4-alpha.getbootstrap.com/layout/grid/#variable-width-content
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col">
I use all the space left
</div>
<div class="col-sm col-sm-auto">
I am a small text on the right
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
小智 28
对于任何从谷歌搜索(像我一样)来到这里的人.
由于引导V4.1版本有flex-grow
和flex-shrink
公用事业,作为文档说,你可以使用它们像这样:
.flex-{grow|shrink}-0
.flex-{grow|shrink}-1
.flex-sm-{grow|shrink}-0
.flex-sm-{grow|shrink}-1
Run Code Online (Sandbox Code Playgroud)
这是一个小例子
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="d-flex flex-row">
<div class="d-flex flex-grow-1 text-white justify-content-center bg-danger">
Grow 1
</div>
<div class="d-flex flex-grow-0 text-white justify-content-center bg-success">
Grow 0
</div>
<div class="d-flex flex-grow-1 text-white justify-content-center bg-danger">
Grow 1
</div>
</div>
Run Code Online (Sandbox Code Playgroud)