I am trying to create a collapsible navbar in Bootstrap. Right now it looks like this picture:
What I want is for the dropdown to only be of a fixed width (not take up the entire screen), to be located at the right instead of at the left, and to nicely center the text vertically inside the menu items. How can I accomplish this?
I have some additional CSS which overrides Bootstraps's defaults from boostrap.min.css. The part that has to do with the navbar is copied below:
.navbar-default {
padding: 10px 0;
-webkit-transition: padding .3s;
-moz-transition: padding .3s;
transition: padding .3s;
font-family: "Kaushan Script","Helvetica Neue",Helvetica,Arial,cursive;
}
.navbar-toggle { /* the toggle is the thing seen on mobile */
border: 0;
margin-top: 0px;
background-color: #{{ site.data.template.color.primary }};
}
/* Using navbar-toggle alone here isn't specific enough for reasons that are
unclear to me, since I use only navbar-toggle above.
https://stackoverflow.com/questions/20540563/change-icon-bar-color-in-bootstrap */
.navbar-default .navbar-toggle:hover,
.navbar-default .navbar-toggle:focus,
.navbar-default .navbar-toggle:active {
background-color: #{{ site.data.template.color.secondary }};
}
.navbar-default .nav li a { /* the buttons in the navbar */
height: 40px;
line-height: 0px;
text-transform: uppercase;
font-family: {{ site.data.template.font.primary }};
font-weight: bold;
letter-spacing: 1px;
color: #fff;
}
.navbar-default .nav li a:hover {
color: #{{ site.data.template.color.primary }};
}
.navbar-default .nav>.active>a:focus {
background-color: #{{ site.data.template.color.primary }};
}
.navbar-default .nav>.active>a:hover {
background-color: #{{ site.data.template.color.secondary }};
}
.navbar-default .navbar-nav>.active>a {
border-radius: 3px;
background-color: #{{ site.data.template.color.primary }};
}
.navbar-default.navbar-shrink { /* This sets the background dark below the welcome */
padding: 10px 0;
background-color: #222;
}
.navbar-brand { /* this keeps the buttons from getting larger below the welcome */
font-size: 1.5em;
}
@media(max-width:768px) {
.navbar-collapse {
width: 120px;
}
.navbar-collapse li a {
background-color: #222;
}
}
And here is the header html
<!-- Navigation -->
<nav class="navbar navbar-default navbar-default-color navbar-fixed-top">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header page-scroll">
<div class="col-md-12">
<ul class="list-inline social-buttons">
{% for link in site.social %}
<li><a href="{{ link.url }}"><i class="{{ link.icon }}"></i></a></li>
{% endfor %}
</ul>
</div>
<button class="navbar-toggle" data-toggle="collapse" data-target="#menu">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="menu">
<ul class="nav navbar-nav navbar-right">
<li class="hidden"><a href="#welcome"></a></li>
<li><a class="page-scroll" href="#about">About</a></li>
<li><a class="page-scroll" href="#projects">Projects</a></li>
<li><a class="page-scroll" href="#writing">Writing</a></li>
<li><a class="page-scroll" href="#contact">Contact</a></li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>