Get rid of second row in bootstrap small view and more
-
20-12-2019 - |
Question
I am trying to make a navigation link to the top as a label for the pulldown button however it keeps putting it on a second row. I finally fixed it so that I can move it right or left and it looks proper after CSS formatting and I attempted to change the way it handles making new rows in that formatting with no success. I am pretty new to html and CSS, have been learning it over the past 3 days.
<style>
.jumbotron{
background-size: cover;
background-position: center;
background-repeat: no-repeat;
height:300px;
color:white !important;
}
#bitcoin{
height: 68px;
width: 68px;
}
.navbar-default .navbar-brand:hover,
.navbar-default .navbar-brand:focus {
color: #777;
}
#cherry{
width: 50px;
}
.navbar-left {float: left !important;}
.navbar-right {float: right !important;}
@media(max-width:767px)
{
.navbar-right {margin-right:20px;}
.navbar-header:after
{
clear: none;
}
.navbar-nav.navbar-right > li { float: left; }
.navbar-collapse:before {clear:both;}
.navbar-collapse {overflow-y: hidden;}
.navbar-collapse.in {overflow-y: visible;}
.navbar-collapse.in > ul {border-top: 1px double #101010;}
}
.navbar-brand {
font-size: 25px;
line-height: 10px;
padding-bottom: 5px;
}
.logo_tagline {
text-transform: uppercase;
font-size: 10px;
letter-spacing: 2px;
color:#bbb;
}
}
<body>
<!-- Navbar -->
<nav class="navbar navbar-default navbar-inverse" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#example-nav-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="navbar-inner">
<a class="brand" href="index.html"> <img id="cherry" src="img/cheery3.svg"></a>
</div>
</div>
<div class="navbar-left">
<ul class="nav navbar-nav visible-xs">
<li><a href="#">Nav</a></li>
</ul>
</div>
<div class="collapse navbar-collapse" id="example-nav-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="index.html">Home</a></li>
<li><a href="#">Bitcoin</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Contact Us</a></li>
</ul>
</div>
</div>
</nav>
</body>
Solution
Keeping the styles that you've already added, you'll need to place the div containing the ul with the Nav text inside the navbar-inner div AND you need to use the visible-xs-inline class. Additionally, since you've floated the ul with the Nav text to the left, you'll also have to float your #cherry div to the left or it will appear on the right of the Nav text.
CSS:
#cherry {
width: 50px;
float: left; /*add this*/
}
HTML:
<!-- Navbar -->
<nav class="navbar navbar-default navbar-inverse" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#example-nav-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="navbar-inner">
<a class="brand" href="index.html"> <img id="cherry" src="img/cheery3.svg"></a>
<div class="navbar-left visible-xs-inline">
<ul class="nav navbar-nav">
<li><a href="#">Nav</a></li>
</ul>
</div>
</div>
</div>
<div class="collapse navbar-collapse" id="example-nav-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="index.html">Home</a></li>
<li><a href="#">Bitcoin</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Contact Us</a></li>
</ul>
</div>
</div>
</nav>