Проблемы с Bootstrap 4 исправленной навигационной панелью - PullRequest
1 голос
/ 16 апреля 2020

У меня есть Bootstrap навигационная панель, которую я хочу, чтобы она была зафиксирована сверху, поэтому при прокрутке содержимого ниже навигационная панель остается на том же месте. Пока это требование работает нормально, но есть две проблемы:

Первая проблема заключается в том, что при выборе элемента из любого из двух раскрывающихся списков их длина изменяется. Я хочу, чтобы длины были фиксированными.

Вторая проблема заключается в том, что мне не нужно, чтобы элементы управления «Тип отчета», «Код» и «Отправить» были разборными. Эта страница будет использоваться исключительно в веб-браузере на настольном компьютере или ноутбуке. Мне просто нужно, чтобы эти три элемента управления были закреплены справа. Это означает, что длина навигационной панели будет фиксированной, и если размер браузера будет уменьшен, пользователю придется прокрутить вправо, чтобы увидеть оставшуюся часть навигационной панели. Как удалить разборную функцию?

Заранее спасибо.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
    integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"
    integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"
    integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"
    integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
<title>Test</title>
</head>
<body>
    <nav class="navbar navbar-expand-lg bg-dark navbar-dark fixed-top">
        <div class="btn-group dropright">
            <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true"
                aria-expanded="false">Reports</button>
            <div class="dropdown-menu">
                <button class="dropdown-item" type="button">Reports</button>
                <button class="dropdown-item" type="button">Settings</button>
                <button class="dropdown-item" type="button">Logout</button>
            </div>
        </div>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarSupportedContent">
            <ul class="navbar-nav mr-auto"></ul> <!-- If I remove this, the controls to the right will shift to the left -->
            <form id="report-form" class="form-inline" action="/test" method="POST">
                <label class="mr-1" for="report_type_button" style="color: white !important;">Report Type:</label>
                <select
                    class="custom-select mr-sm-3" id="report-type-button">
                    <option value="IMRS" selected>XXX Report</option>
                    <option value="IMRF">YYY Report</option>
                </select> <label class="mr-1" for="report_type_button" style="color: white !important;">Code:</label>
                <div class="dropdown mr-sm-3">
                    <button class="btn btn-primary btn-block dropdown-toggle" type="button" data-toggle="dropdown">AAAAA</button>
                    <div class="dropdown-menu">
                        <button class="dropdown-item" type="button">AAAAA</button>
                        <button class="dropdown-item" type="button">BBBBB BBBBB</button>
                        <button class="dropdown-item" type="button">CCCCC CCCCC CCCCC</button>
                    </div>
                </div>
                <button type="submit" class="btn btn-primary " onclick="submitForm()">Submit</button>
                <input id="unit-code" name="unitCode" type="hidden" value="" /> <input id="report-date" name="reportDate"
                    type="hidden" value="" />
            </form>
        </div>
    </nav>
    <div class="container-fluid" style="padding-top: 70px;">
        <table class="table table-hover small">
            <thead class="thead-dark">
                <tr>
                    <th scope="col" colspan="4" class="border-0">Report ID: ABCDEFG</th>
                    <th scope="col" colspan="4" class="border-0" style="text-align: center">XXX Report</th>
                    <th scope="col" colspan="4" class="border-0" style="text-align: right">Page: 1 / 1</th>
                </tr>
                <tr>
                    <th scope="col" colspan="3" class="border-0">Report Date: 16/04/2020</th>
                    <th scope="col" colspan="9" class="border-0" style="text-align: right">Updated Time: 16/04/2020 11:30:58</th>
                </tr>
                <tr>
                    <th class="align-top" scope="col">I/O</th>
                    <th class="align-top" scope="col">Sender</th>
                    <th class="align-top" scope="col">Receiver</th>
                    <th class="align-top" scope="col">Type</th>
                    <th class="align-top" scope="col">ID</th>
                    <th class="align-top" scope="col">Reference</th>
                    <th class="align-top" scope="col">Currency</th>
                    <th class="align-top" scope="col">Amount</th>
                    <th class="align-top" scope="col">Value Date</th>
                    <th class="align-top" scope="col">Acceptance Time</th>
                    <th class="align-top" scope="col">Last Updated Time</th>
                    <th class="align-top" scope="col">Status</th>
                </tr>
            </thead>
            <tbody>
                <tr class="table-warning">
                    <td nowrap>I</td>
                    <td nowrap>XXXXXXXXXXX</td>
                    <td nowrap>YYYYYYYYYYY</td>
                    <td nowrap>XXXX</td>
                    <td nowrap>ZZZZZZZZZZZZZZZZZZZZZZZZZZZZ</td>
                    <td nowrap>AAAAAAAAAAAAAA</td>
                    <td nowrap>USD</td>
                    <td nowrap>1000.00</td>
                    <td nowrap>16/04/2020</td>
                    <td nowrap>16/04/2020 11:30:58</td>
                    <td nowrap>16/04/2020 11:30:58</td>
                    <td nowrap>DUP</td>
                </tr>
            </tbody>
        </table>
    </div>
    <script>
        $('.dropdown-item').on('click', function() {
            var btnObj = $(this).parent().siblings('button');
            $(btnObj).text($(this).text());
            $(btnObj).val($(this).text());
        });
    </script>
</body>
</html>

EDITED :

Я хочу, чтобы элементы управления оставались в одном ряду, но если я изменю размер браузера, чтобы уменьшить ширину, элементы управления перетекут в следующую строку.

enter image description here

Ответы [ 2 ]

1 голос
/ 17 апреля 2020

Вот решение.

Для fixed-dropdown я добавил fixed_dropdown класс в dropdown-btn.

Для fixed navbar и non-collapsable, вы можете использовать fixed-top и navbar-expand класс.

что вы имеете в виду в одной строке?

.fixed_dropdown {
    width: 10rem;
    white-space: normal;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
    integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"
    integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"
    integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"
    integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
<title>Test</title>
</head>
<body>
    <nav class="navbar navbar-expand bg-dark navbar-dark fixed-top">
        <div class="btn-group dropright">
            <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true"
                aria-expanded="false">Reports</button>
            <div class="dropdown-menu">
                <button class="dropdown-item" type="button">Reports</button>
                <button class="dropdown-item" type="button">Settings</button>
                <button class="dropdown-item" type="button">Logout</button>
            </div>
        </div>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarSupportedContent">
            <ul class="navbar-nav mr-auto"></ul> <!-- If I remove this, the controls to the right will shift to the left -->
            <form id="report-form" class="form-inline" action="/test" method="POST">
                <label class="mr-1" for="report_type_button" style="color: white !important;">Report Type:</label>
                <select
                    class="custom-select mr-sm-3" id="report-type-button">
                    <option value="IMRS" selected>XXX Report</option>
                    <option value="IMRF">YYY Report</option>
                </select> <label class="mr-1" for="report_type_button" style="color: white !important;">Code:</label>
                <div class="dropdown mr-sm-3">
                    <button class="btn btn-primary btn-block dropdown-toggle fixed_dropdown" type="button" data-toggle="dropdown">AAAAA</button>
                    <div class="dropdown-menu">
                        <button class="dropdown-item" type="button">AAAAA</button>
                        <button class="dropdown-item" type="button">BBBBB BBBBB</button>
                        <button class="dropdown-item" type="button">CCCCC CCCCC CCCCC</button>
                    </div>
                </div>
                <button type="submit" class="btn btn-primary " onclick="submitForm()">Submit</button>
                <input id="unit-code" name="unitCode" type="hidden" value="" /> <input id="report-date" name="reportDate"
                    type="hidden" value="" />
            </form>
        </div>
    </nav>
    <div class="container-fluid" style="padding-top: 70px;">
        <table class="table table-hover small">
            <thead class="thead-dark">
                <tr>
                    <th scope="col" colspan="4" class="border-0">Report ID: ABCDEFG</th>
                    <th scope="col" colspan="4" class="border-0" style="text-align: center">XXX Report</th>
                    <th scope="col" colspan="4" class="border-0" style="text-align: right">Page: 1 / 1</th>
                </tr>
                <tr>
                    <th scope="col" colspan="3" class="border-0">Report Date: 16/04/2020</th>
                    <th scope="col" colspan="9" class="border-0" style="text-align: right">Updated Time: 16/04/2020 11:30:58</th>
                </tr>
                <tr>
                    <th class="align-top" scope="col">I/O</th>
                    <th class="align-top" scope="col">Sender</th>
                    <th class="align-top" scope="col">Receiver</th>
                    <th class="align-top" scope="col">Type</th>
                    <th class="align-top" scope="col">ID</th>
                    <th class="align-top" scope="col">Reference</th>
                    <th class="align-top" scope="col">Currency</th>
                    <th class="align-top" scope="col">Amount</th>
                    <th class="align-top" scope="col">Value Date</th>
                    <th class="align-top" scope="col">Acceptance Time</th>
                    <th class="align-top" scope="col">Last Updated Time</th>
                    <th class="align-top" scope="col">Status</th>
                </tr>
            </thead>
            <tbody>
                <tr class="table-warning">
                    <td nowrap>I</td>
                    <td nowrap>XXXXXXXXXXX</td>
                    <td nowrap>YYYYYYYYYYY</td>
                    <td nowrap>XXXX</td>
                    <td nowrap>ZZZZZZZZZZZZZZZZZZZZZZZZZZZZ</td>
                    <td nowrap>AAAAAAAAAAAAAA</td>
                    <td nowrap>USD</td>
                    <td nowrap>1000.00</td>
                    <td nowrap>16/04/2020</td>
                    <td nowrap>16/04/2020 11:30:58</td>
                    <td nowrap>16/04/2020 11:30:58</td>
                    <td nowrap>DUP</td>
                </tr>
            </tbody>
        </table>
    </div>
    <script>
        $('.dropdown-item').on('click', function() {
            var btnObj = $(this).parent().siblings('button');
            $(btnObj).text($(this).text());
            $(btnObj).val($(this).text());
        });
    </script>
</body>
</html>
0 голосов
/ 16 апреля 2020

Прежде всего удалите класс .navbar-expand-lg из тега навигации, так как вы не хотите сворачивать панель навигации в любой точке останова.
Также вам не нужно добавлять кнопку .navbar-toggler. Это создаст кнопку гамбургера для переключения ваших свернутых элементов, в вашем случае элементов внутри #navbarSupportedContent. Поэтому удалите следующее:

 <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
 </button>

Также удалите из этого класса .collapse и .navbar-collapse:

<div class="collapse navbar-collapse" id="navbarSupportedContent">

Надеюсь, это поможет.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...