I am currently working on designing a Bootstrap navbar that features the navigation items on the left side and the social/contact icons on the right. My goal is to have the nav items collapse when needed, but have the social/contact items remain visible for easy access on mobile devices.
After researching solutions for similar issues, I discovered that Bootstrap v4 is not backward compatible, rendering previous solutions ineffective.
My code structure appears to be straightforward. Placing the social/contact items in a separate div outside the collapse div results in a strange layout. However, when I include them within the collapse div, they align correctly. Unfortunately, they collapse along with the nav items, which is not the desired outcome. I attempted to adjust the flex parameters without success.
In an ideal mobile view scenario, I envision having only the social/contact icons and the hamburger menu button displayed on the right side.
#phone-number {
padding: 0 1em;
font-weight: bold;
}
.navbar-right {
flex-direction: row;
}
@media (max-width: 767px) {
#phone-number {
display: none;
}
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta/js/bootstrap.min.js"></script>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="#">Navbar</a> <button aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation" class="navbar-toggler" data-target="#navbarTogglerDemo02" data-toggle="collapse" type="button"><span class="navbar-toggler-icon"></span></button>
<div class="collapse navbar-collapse" id="navbarTogglerDemo02">
<div class="navbar-nav mr-auto mt-2 mt-lg-0">
<a class="nav-item nav-link" href="#">Home <span class="sr-only">(current)</span></a>
<a class="nav-item nav-link" href="#">Link</a> <a class="nav-item nav-link" href="#">Disabled</a>
</div>
</div>
<div class="nav navbar-nav navbar-right">
<a class="nav-item nav-link" href="#"><i class="fa fa-envelope fa-lg"></i></a>
<a class="nav-item nav-link" href="#"><i class="fa fa-phone fa-lg"></i><span id='phone-number'>509-123-4567</span></a>
<a class="nav-item nav-link" href="#"><i class="fa fa-twitter color-twitter fa-lg"></i></a>
<a class="nav-item nav-link" href="#"><i class="fa fa-facebook color-facebook fa-lg"></i></a>
<a class="nav-item nav-link" href="#"><i class="fa fa-linkedin color-linkedin fa-lg"></i></a>
</div>
</nav>
<br/><br/><br/>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="#">Navbar</a> <button aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation" class="navbar-toggler" data-target="#navbarTogglerDemo02" data-toggle="collapse" type="button"><span class="navbar-toggler-icon"></span></button>
<div class="collapse navbar-collapse" id="navbarTogglerDemo02">
<div class="navbar-nav mr-auto mt-2 mt-lg-0">
<a class="nav-item nav-link" href="#">Home <span class="sr-only">(current)</span></a>
<a class="nav-item nav-link" href="#">Link</a> <a class="nav-item nav-link" href="#">Disabled</a>
</div>
<div class="nav navbar-nav navbar-right">
<a class="nav-item nav-link" href="#"><i class="fa fa-envelope fa-lg"></i></a>
<a class="nav-item nav-link" href="#"><i class="fa fa-phone fa-lg"></i><span id='phone-number'>509-123-4567</span></a>
<a class="nav-item nav-link" href="#"><i class="fa fa-twitter color-twitter fa-lg"></i></a>
<a class="nav-item nav-link" href="#"><i class="fa fa-facebook color-facebook fa-lg"></i></a>
<a class="nav-item nav-link" href="#"><i class="fa fa-linkedin color-linkedin fa-lg"></i></a>
</div>
</div>
</nav>