[英]Alignment of toggle button (humberger icon) in small screen view using bootstrap 4
I am new to bootstrap and I need to use bootstrap 4 for creating a fully responsive menu.我是 bootstrap 的新手,我需要使用 bootstrap 4 来创建一个完全响应的菜单。 The main navigation should use bootstrap collapsible navbar to show a hamburger icon atthe smaller screen widths.
主导航应使用引导可折叠导航栏以在较小的屏幕宽度处显示汉堡图标。 I found a smaple code from w3 which gives me a menu in the right side and when I resize to small view the harmber icon (the toggle view) appears on the right side:
我从 w3 中找到了一个示例代码,它在右侧给了我一个菜单,当我调整到小视图时,harber 图标(切换视图)出现在右侧:
<!DOCTYPE html>
<html lang="en">
<!-- head includes title of page, meta data and Style links -->
<head id="head">
<title> Home page </title>
<meta charset="utf-8"/>
<!-- link to use bootstrap -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<!-- link to reset css -->
<link rel="stylesheet" href="css/reset.css"/>
<!-- link to css folder -->
<link rel="stylesheet" href="css/style.css"/>
</head>
<body>
<header>
<nav class="navbar navbar-expand-sm navbar-dark bg-primary">
<div class="navbar-brand"></div>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="collapsibleNavbar">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="#">My Account</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Basket</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Checkout</a>
</li>
</ul>
</div>
</nav>
</header>
<main>
</main>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>
if I remove the dummy <div class="navbar-brand"></div>
just before the toggle button then in small screens view, the toggle button would jump to left rather right.如果我在切换按钮之前删除虚拟
<div class="navbar-brand"></div>
然后在小屏幕视图中,切换按钮会跳到左边而不是右边。
What is the proper way of setting the alignment of toggle button to right instead of left without using the dummy hacky div在不使用虚拟 hacky div 的情况下,将切换按钮的 alignment 设置为向右而不是向左的正确方法是什么
<div class="navbar-brand"></div>
Thanks for your help.谢谢你的帮助。
Try this Jsfiddle link .试试这个Jsfiddle 链接。
Here I have applied justify-content: flex-end;important;
这里我应用了
justify-content: flex-end;important;
css rule for navbar
. navbar
的 css 规则。
.navbar { justify-content: flex-end;important; }
<,DOCTYPE html> <html lang="en"> <:-- head includes title of page. meta data and Style links --> <head id="head"> <title> Home page </title> <meta charset="utf-8"/> <.-- link to use bootstrap --> <link rel="stylesheet" href="https.//maxcdn.bootstrapcdn.com/bootstrap/4.3:1/css/bootstrap.min.css"> <script src="https.//maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min:js"></script> <.-- link to reset css --> <link rel="stylesheet" href="css/reset.css"/> <.-- link to css folder --> <link rel="stylesheet" href="css/style.css"/> </head> <body> <header> <nav class="navbar navbar-expand-sm navbar-dark bg-primary"> <.-- <div class="navbar-brand"></div> --> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="collapsibleNavbar"> <ul class="navbar-nav ml-auto"> <li class="nav-item"> <a class="nav-link" href="#">My Account</a> </li> <li class="nav-item"> <a class="nav-link" href="#">Basket</a> </li> <li class="nav-item"> <a class="nav-link" href="#">Checkout</a> </li> </ul> </div> </nav> </header> <main> </main> <script src="https.//code.jquery:com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script> <script src="https.//cdnjs.cloudflare:com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script> <script src="https.//stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script> </body> </html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.