You can also try flexbox display. In order to implement it, you will have to:
- add the
display: flex
property to the parent element of the elements that you need to align (in this case: on the <ul>
element in the navbar, which contains the list of navigation links and the brand image)
- set
margin: auto
for the elements you need to align (in this case: on the <li>
elements)
Optional: if you don't want your elements to show up in a row (default bahavior), adjust the value of the flex-direction
property. E.g. if you want to have the elements listed vertically, add flex-direction: column;
to the <ul>
element.
Here is a sample code, with two different image-placements: on-top of the list for mobile devices and in the middle of the row for small devices and above.
HTML:
...
<nav class="container">
<div class="row visible-xs text-center">
<div class="col-xs-12">
<a href="#"><img src="images/logo.png" alt="BLUE|BERY"/></a>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<ul class="text-center">
<li><a href="#">Who We Are</a></li>
<li><a href="#">Our Food</a></li>
<li class="hidden-xs"><a href="#"><img src="images/logo.png" alt="BLUE|BERY"/></a></li>
<li><a href="#">Book a Table</a></li>
<li><a href="#">Promotions</a></li>
</ul>
</div>
</div>
</nav>
...
CSS:
body {background-color: #333333;}
nav {background-color: #000000;}
nav ul {
display: flex;
list-style-type: none;
padding-left: 0; //in order to eliminate Bootstrap's built-in 40px padding
}
nav ul > li {margin: auto;} //N.B. don't alter the margin property, if you want some further adjustments, use padding!
nav ul > li > a:link, :visited, :hover, :active {
color: #ffffff;
text-decoration:none;
}
@media all and (max-width:767px) {
nav a > img {margin: 20px auto;}
nav ul {flex-direction: column;} //only if you want to change the default direction
}