我想知道如何将nav
栏移到右侧。截至目前,使用我发布的当前HTML,它会显示左侧导航栏中的所有项目。我想将一些项目放在右边,但我不知道该怎么做。例如,我应该使用CSS吗?或者我应该在bootstrap中使用关键字?请注意我使用的是bootstrap。
HTML
<nav class="navbar navbar-expand-md navbar-dark bg-dark ">
<a class="navbar-brand" href="index.html">Store Shop</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse ml-auto" id="navbarsExampleDefault">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="index.html">Home
<span class="sr-only">(current)</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="register.html">Create Account</a>
</li>
</ul>
<div class="navmoveright">
<form class="form-inline my-2 my-lg-0" id="navmoveright">
<input class="form-control mr-sm-2" name="username" type="text" placeholder="Enter Username" aria-label="Enter Username">
<input class="form-control mr-sm-2" name="password" type="password" placeholder="Enter Password" aria-label="Enter Password">
<button class="btn btn-outline-success my-2 my-sm-0" name="submit" type="submit">Login</button>
<ul class="nav navbar-nav navbar-right mr-auto" id="navmoveright">
<li>
<a href="#">
<span class="glyphicon glyphicon-shopping-cart" aria-hidden="true"></span> Cart (0)</a>
</li>
</ul>
</form>
</div>
</div>
</nav>
CSS
.navmoveright{
float:right;
position:fixed;
top:0px;
right:0px;
text-align: right;
}
答案 0 :(得分:0)
添加此css
.navmoveright
{
float:right;
}
我希望这会有所帮助
答案 1 :(得分:0)
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" >
看来问题出在我所放置的两个CDN上。删除4.0版本后,代码和语法能够按照它的方式工作。换句话说,两个cdn似乎相互冲突。