Как выровнять bootstrap 4, горизонтальный список группы в центре - PullRequest
0 голосов
/ 26 декабря 2018

Я использую этот фрагмент кода из здесь (показано ниже) для горизонтального выравнивания элементов в группе списков (в Bootstrap 4).

    .list-group.list-group-horizontal{
        display: flex;
        flex-direction: row;
    }

    .list-group.list-group-horizontal .list-group-item {
        margin-bottom: 0;
        margin-right: 0;
        border-right-width: 0;
    }
    .list-group.list-group-horizontal .list-group-item:first-child {
        border-top-right-radius:0;
        border-bottom-left-radius:4px;
    }
    .list-group.list-group-horizontal .list-group-item:last-child {
        border-top-right-radius:4px;
        border-bottom-left-radius:0;
        border-right-width: 1px;
    }

Как мне отцентрироватьвыровнять список группы?Я попытался добавить класс text-center и некоторые другие вещи, однако мне это не удалось.

<div id="app" class="container my-container">

    <!-- Header -->
    <h2 class="text-center" >Sample Header</h2>

    <!-- Buttons -->
    <div class="list-group list-group-horizontal">
        <a href="#" class="list-group-item active">Categories</a>
        <a href="#" class="list-group-item">Search</a>
    </div>

</div>

Codepen

Ответы [ 2 ]

0 голосов
/ 26 декабря 2018

Используйте Обоснуйте содержание , чтобы изменить горизонтальное расположение ваших элементов:

.list-group.list-group-horizontal {
    display: flex;
    flex-direction: row;
}

.list-group.list-group-horizontal .list-group-item {
    margin-bottom: 0;
    margin-right: 0;
    border-right-width: 0;
}

.list-group.list-group-horizontal .list-group-item:first-child {
    border-top-right-radius:0;
    border-bottom-left-radius:4px;
}

.list-group.list-group-horizontal .list-group-item:last-child {
    border-top-right-radius:4px;
    border-bottom-left-radius:0;
    border-right-width: 1px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<div id="app" class="container">

    <!-- Header -->
    <h2 class="text-center" >Sample Header</h2>

    <!-- Buttons -->
    <div class="list-group list-group-horizontal d-flex justify-content-center">
        <a href="#" class="list-group-item active">Categories</a>
        <a href="#" class="list-group-item">Search</a>
    </div>
</div>
0 голосов
/ 26 декабря 2018

Для потомков: Применить d-flex justify-content-center, если ваш элемент не является гибким элементом.

Оригинальный ответ: Применить justify-content-center к list-group

Codepen: https://codepen.io/anon/pen/gZRzOR

Вот это в документации: https://getbootstrap.com/docs/4.0/utilities/flex/#justify-content

<div class="list-group list-group-horizontal justify-content-center">
....
....
</div>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...