我有一个Bootstrap导航栏,我希望将其固定在顶部,因此当滚动下面的内容时,导航栏将保留在同一位置。到目前为止,此要求可以正常工作,但是存在两个问题:
第一个问题是,当我从两个下拉列表中的任何一个中选择一个项目时,它们的长度都会改变。我希望长度固定。
第二个问题是,我不需要“报表类型”,“代码”和“提交”控件即可折叠。此页面将仅在台式机或笔记本电脑上的Web浏览器上使用。我只需要将这三个控件固定在右侧即可。这意味着导航栏的长度将是固定的,并且如果将浏览器的大小调整得更小,则用户将不得不向右滚动以查看导航栏的其余部分。如何删除可折叠功能?
提前感谢。
<!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/[email protected]/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>
首先,从导航标签中删除.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">
希望对您有帮助。
这里是解决方案。
对于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/[email protected]/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>