Свернуть Boostrap 4: название и значок не на одной линии - PullRequest
1 голос
/ 27 сентября 2019

Рассмотрим этот коллапс на 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>

Мне бы хотелось, чтобы заголовок и значок были на одной строке , но только если заголовок в одну строку. Я довольно близок к достижению того, чего хочу, но независимо от того, что я пытаюсь, всегда есть проблема. Любая помощь действительно будет оценена.

Хорошо: введите описание изображения здесь

Ok: введите описание изображения здесь

Not Ok : введите описание изображения здесь

ОК: введите описание изображения здесь

Большое спасибо! Извините за мой английский ...

1 Ответ

0 голосов
/ 28 сентября 2019

Это может быть достигнуто с помощью 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;
}

демо: https://jsfiddle.net/davidliang2008/avrp6j9f/8/

Скриншоты

enter image description here

enter image description here

enter image description here

enter image description here

...