我用Bootstrap4创建了一个响应导航栏。当屏幕很大时,有两个按钮。当屏幕很小的时候,就会有汉堡包菜单。
[在此处输入图像描述][1][在此处键入图像描述][2]
我如何在导航栏中设置元素的样式,使它们在汉堡菜单中看起来不再像按钮?
谢谢!
这是我的代码:
<a class="navbar-brand" href="index.html">MyJobBoard</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo02" aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarTogglerDemo02">
<ul class="navbar-nav navbar-right ml-auto mt-2 mt-lg-0 float-right text-right">
<li class="nav-item active">
<a class="nav-link post-a-job-button pull-right">Create a profile</a>
</li>
<li class="nav-item">
<button type="button" class="btn btn-light mr-3 pull-right">Sign In</button>
</li>
<li class="nav-item">
<button type="button" class="btn btn-primary mr-3 pull-right">Post a Job</button>
</li>
</ul>
</div>
</nav> ```
[1]: https://i.stack.imgur.com/ujYIG.png
[2]: https://i.stack.imgur.com/lE4ib.png
一个解决方案是将所有导航项目构建为链接,这样在较小的屏幕上,您将拥有正常的Bootstrap向下滑动菜单,然后是应用于较大显示器的自定义按钮类。
如果你的登录和离职后表格在一个单独的页面上,那么你可以使用到另一个页面的直接链接,但如果你使用模态来显示表格,那么你需要使用JavaScript来打开模态。
我在下面的例子中禁用了post-a-job按钮,这样你就可以看到如何禁用按钮,这样没有登录的人就不能发布作业了。
$('a[href$="#signInModal"]').on("click", function() {
$("#signInModal").modal('show');
});
$('a[href$="#postJobModal"]').on("click", function() {
$("#postJobModal").modal('show');
});
<link href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js"></script>
<style>
@media (min-width:768px) {
.btn-md {
display: inline-block;
font-weight: 400;
color: #212529;
text-align: center;
vertical-align: middle;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
background-color: transparent;
border: 1px solid transparent;
padding: .375rem .75rem;
font-size: 1rem;
line-height: 1.5;
border-radius: .25rem;
transition: color .15s ease-in-out, background-color .15s ease-in-out, border-color .15s ease-in-out, box-shadow .15s ease-in-out;
}
.btn-primary-md {
color: #fff;
background-color: #007bff;
border-color: #007bff;
}
.navbar-light .navbar-nav .nav-link {
color: #fff;
}
.navbar-light .navbar-nav .nav-link.disabled {
color: rgba(255, 255, 255, 0.6);
}
.btn-md:not(:disabled):not(.disabled) {
cursor: pointer;
}
}<nav class="navbar navbar-expand-md navbar-light bg-light">
<!-- Container wrapper -->
<div class="container-fluid">
<!-- Navbar brand -->
<a class="navbar-brand" href="index.html">MyJobBoard</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo02" aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarTogglerDemo02">
<ul class="navbar-nav navbar-right ml-auto mt-2 mt-lg-0 float-right text-right">
<li class="nav-item active">
<a class="nav-link post-a-job-button mr-md-3" href="#">Create a profile</a>
</li>
<li class="nav-item">
<a class="nav-link btn-md btn-primary-md mr-md-3 text-white-md" href="#signInModal" role="button" style="width: 6.125rem">Sign In</a>
</li>
<li class="nav-item">
<a class="nav-link btn-md btn-primary-md mr-md-3 text-white-md disabled" href="#postJobModal" role="button" style="width: 6.125rem" tabindex="-1" aria-disabled="true">Post a Job</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="modal fade" id="signInModal" tabindex="-1" aria-labelledby="signInModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="signInModalLabel">Sign In</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p>Form for signing in (or registering) goes here.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary">Sign in</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="postJobModal" tabindex="-1" aria-labelledby="postJobModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="postJobModalLabel">Post a job</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p>Form for posting a job</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary">Post</button>
</div>
</div>
</div>
</div>
</style>
<nav class="navbar navbar-expand-md navbar-light bg-light">
<!-- Container wrapper -->
<div class="container-fluid">
<!-- Navbar brand -->
<a class="navbar-brand" href="index.html">MyJobBoard</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo02" aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarTogglerDemo02">
<ul class="navbar-nav navbar-right ml-auto mt-2 mt-lg-0 float-right text-right">
<li class="nav-item active">
<a class="nav-link post-a-job-button mr-md-3" href="#">Create a profile</a>
</li>
<li class="nav-item">
<a class="nav-link btn-md btn-primary-md mr-md-3 text-white-md" href="#signInModal" role="button" style="width: 6.125rem">Sign In</a>
</li>
<li class="nav-item">
<a class="nav-link btn-md btn-primary-md mr-md-3 text-white-md disabled" href="#postJobModal" role="button" style="width: 6.125rem" tabindex="-1" aria-disabled="true">Post a Job</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="modal fade" id="signInModal" tabindex="-1" aria-labelledby="signInModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="signInModalLabel">Sign In</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p>Form for signing in (or registering) goes here.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary">Sign in</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="postJobModal" tabindex="-1" aria-labelledby="postJobModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="postJobModalLabel">Post a job</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p>Form for posting a job</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary">Post</button>
</div>
</div>
</div>
</div>