考虑此boostrap 4崩溃(https://codepen.io/jaysarf/pen/xxKNKvX):
<div class="card">
<h5 class="card-header">
<a data-toggle="collapse" href="#collapse-example" aria-expanded="true" aria-controls="collapse-example" id="heading-example" class="d-block">
<i class="fa fa-chevron-down fa-pull-right"></i>This is a loooooooooooooooooooooooooooooooooooooooong collapsible title<span class="ml-1 my-1 badge badge-success float-right">This is a pretty loooooong badge text</span>
</a>
</h5>
<div id="collapse-example" class="collapse show" aria-labelledby="heading-example" style="">
<div class="card-body">
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon
officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3
wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et.
Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan
excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt
you probably haven't heard of them accusamus labore sustainable VHS.
</div>
</div>
我希望标题和徽章在同一行但仅如果标题在一行上。我几乎可以实现我想要的,但是无论我尝试什么,总会有问题。任何帮助将不胜感激。
确定:enter image description here
确定:enter image description here
不正常:enter image description here
确定:enter image description here
非常感谢!对不起,我的英语...
可以通过flexbox实现。
HTML结构需要稍作更改:
<h5 class="card-header">
<a data-toggle="collapse" href="#collapse-example" aria-expanded="true"
aria-controls="collapse-example" class="card-header-collapse">
<span class="card-header-title">
This is a loooooooooooooooooooooooooooooooooooooooong collapsible title
</span>
<span class="card-header-badge">
<span class="badge badge-success">This is a pretty loooooong badge text</span>
<i class="fa fa-chevron-down"></i>
</span>
</a>
</h5>
然后您可以应用CSS将.card-header-collapse
制成flexbox:
.card-header-collapse {
display: flex;
flex-flow: row wrap;
justify-content: space-between;
}
.card-header-badge {
margin-left: auto;
}