Keep search on navbar when collapsed - css

I'm trying to maintain a search bar on the right of my navbar when the menu is collapsed, but can't seem to get it just how I want it.
I want the search on the right for the full menu like this:
And for it to collapse looking like this:
The best I can achieve has the search dialog wrapping to the next line and looks horrible.

To achieve this, you'll need to take the <form> out of .navbar-collapse and use #media queries to position the search box where you want.
#media (min-width: 320px) and (max-width: 899px) {
.navbar-search {
padding: 0;
position: absolute;
top: 0;
right: 100px;
}
}
#media (min-width: 900px) {
.navbar-search {
position: absolute;
top: 0;
right: 40px;
}
}
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Logo</a>
</div>
<!-- Collect the nav links and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active">Link <span class="sr-only">(current)</span></li>
<li>Link</li>
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li role="separator" class="divider"></li>
<li>Separated link</li>
<li role="separator" class="divider"></li>
<li>One more separated link</li>
</ul>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
<!-- Search form goes here out side of .navbar-collapse -->
<form class="navbar-form navbar-search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default hidden-xs hidden-sm">Submit</button>
</form>
</div>
<!-- /.container-fluid -->
</nav>
Here's a working codepen example for you to review. http://codepen.io/yongchuc/pen/dpxeEg

Related

navbar dropdown menus display issue on mobile and small devices with media query

Not a big expert in CSS and responsiveness design, I try to collapse my navbar using a media query. The issue is that for dropdown menus, the responsive design is not applied correctl : The dropdown menus are displayed like on a large desktop device.
What I want is this :
Result Expected
But the result I obtain is this :
Current result
My code is actually the following :
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> <span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button> <a class="navbar-brand" href="#">Brand</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active">Link <span class="sr-only">(current)</span>
</li>
<li>Link
</li>
<li class="dropdown"> Dropdown <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Action
</li>
<li>Another action
</li>
<li>Something else here
</li>
<li class="divider"></li>
<li>Separated link
</li>
<li class="divider"></li>
<li>One more separated link
</li>
</ul>
</li>
</ul>
<form class="navbar-form navbar-left" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<ul class="nav navbar-nav navbar-right">
<li>Link
</li>
<li class="dropdown"> Dropdown <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Action
</li>
<li>Another action
</li>
<li>Something else here
</li>
<li class="divider"></li>
<li>Separated link
</li>
</ul>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
And my media query is the current one as I found googling the web :
#media (max-width: 992px) {
.navbar-header {
float: none;
}
.navbar-left,.navbar-right {
float: none !important;
}
.navbar-toggle {
display: block;
}
.navbar-collapse {
border-top: 1px solid transparent;
box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
}
.navbar-fixed-top {
top: 0;
border-width: 0 0 1px;
}
.navbar-collapse.collapse {
display: none!important;
}
.navbar-nav {
float: none!important;
margin-top: 7.5px;
}
.navbar-nav>li {
float: none;
}
.navbar-nav>li>a {
padding-top: 10px;
padding-bottom: 10px;
}
.collapse.in{
display:block !important;
}
}
Additional info : The menu is displayed well when the viewport size is under 768px.
I guess, there is something missing on my media query for handling the dropdown menu case but I don't know what it is ? Can somebody help me ?
Thanks a lot.
here is your fiddle just remove default style dropdown
jsfiddle.net/qxgy6L9b/18/

Nav bar disappears at 769px width

I am using the Bootstrap navbar-fixed-top method to create a floating nav bar.
I have a few issues I cannot figure out:
Why are my logo and my social icons disappearing when I reduce screen-width to 769px?
Why is my logo and social icons right at the top of the page?
My social icons are too small and bunched up next to each other. How do I change this?
http://codepen.io/dhruvghulati/pen/qrdNBm
What should I do to have a persistent nav bar which is more standard?
.collapse class looks like this:
.collapse {
display: none;
visibility: hidden;
}
And there is:
#media (min-width: 768px)
.navbar-collapse.collapse {
display: block!important;
height: auto!important;
padding-bottom: 0;
overflow: visible!important;
visibility: visible!important;
}
Which means .collapse will be not displayed until screen is 768px width.
Also there is (used for logo):
#media (min-width: 768px)
.navbar-left {
float: left!important;
}
That makes logo float left since screen is 768px width, there is similar class for .navbar-right which is used for social icons container.
You should probably visit the official Bootstrap docs to get more information on navbars. I would use this as the template for your navbar and go from there:
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Brand</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active">Link <span class="sr-only">(current)</span></li>
<li>Link</li>
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li role="separator" class="divider"></li>
<li>Separated link</li>
<li role="separator" class="divider"></li>
<li>One more separated link</li>
</ul>
</li>
</ul>
<form class="navbar-form navbar-left">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<ul class="nav navbar-nav navbar-right">
<li>Link</li>
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li role="separator" class="divider"></li>
<li>Separated link</li>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
Essentially, Bootstrap replaces your nav link with a hamburger button at that screen size. Also, you should give the logo the proper classes (from the code above) to make sure it's always visible. To make the navbar stick to the top of the page, simply add the navbar-fixed-top class to the nav tag. the opening tag should now look like this: <nav class="navbar navbar-default navbar-fixed-top">.
I think its because you are using position:absolute; try using position: relative; instead

how to change navbar bootstrap height and make the text keep in the middle? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
There're so many ways I've tried to edit bootstrap navbar. Actually, for changing the color, and costuming its height had already done. However, the texts left behind.this is the case.
EDIT:
If you want to make the navbar less than 50px you need to override css property min-height in .navbar-default from bootstrap.
JSFiddle
Note:
This will affect your hamburger menu in smaller devices though. You could make it smaller in 768px and above without defining the min-height in .navbar default, but doing it in a media query, like this:
#media (min-width:768px) {
.navbar-default {
min-height:30px;
}
}
SOLUTION:
When you change your navbar's height, vertical aligning the anchors can be done doing the following:
Remove the top and bottom padding from the anchors.
Set the anchor's line-height with the same value as your navbar's height.
JSFiddle
CODE SNIPPET:
.navbar-default {
height: 80px;
}
.navbar-default .navbar-nav > li > a,
.navbar-brand {
padding-top: 0;
padding-bottom: 0;
line-height: 80px;
}
.navbar-form {
margin-top: 22px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Brand</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active">Link <span class="sr-only">(current)</span>
</li>
<li>Link
</li>
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu">
<li>Action
</li>
<li>Another action
</li>
<li>Something else here
</li>
<li role="separator" class="divider"></li>
<li>Separated link
</li>
<li role="separator" class="divider"></li>
<li>One more separated link
</li>
</ul>
</li>
</ul>
<form class="navbar-form navbar-left" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<ul class="nav navbar-nav navbar-right">
<li>Link
</li>
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu">
<li>Action
</li>
<li>Another action
</li>
<li>Something else here
</li>
<li role="separator" class="divider"></li>
<li>Separated link
</li>
</ul>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>

CSS - Bootstrap - Navbar width narrowed mobile button

How to change navbar/container width? Bootstrap 3
While following this I am super confused.
I am still fairly new in CSS, so I am still playing around a lot with bootstrap.
I added a div right outside of the navbar div to contain the total width.
.navbar-outer {
width:1000px;
margin-left: auto;
margin-right: auto;
}
That worked well, but as soon as I narrow the browser. The "Mobile" button no longer shows. Any suggestion on changes while keeping everything intact in the css? This is for bootstrap 3.3.4.
Full code below:
<nav class="navbar navbar-default">
<div class="navbar-outer">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Brand</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="dropdown">
Action <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
<li class="divider"></li>
<li>One more separated link</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<form class="navbar-form navbar-left" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<li class="dropdown">
<img src="testimage.jpg" style="width: 25px; height: 25px;" alt="..." class="img-circle"> Me <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</div>
</nav>
I think it might be that you are setting the width with px, meaning the collapsing feature of the Bootstrap navbar cannot be triggered. I believe it collapses at 768px.
Using min-width and max-width:
.navbar-outer {
max-width:1000px;
min-width:767px;
margin-left: auto;
margin-right: auto;
}
http://jsfiddle.net/frank184/m3n3r1tg/

Bootstrap collapse nav not working in custom wordpress theme

I've looked at tons of examples and have done research and am very stuck.
I am building a custom wordpress theme using the html5 blank and bootstrap CDN. I am trying to collapse my nav in the responsive sizes. I am able to get it to collapse and create the button, however I can not get it expose the content.
Here is my html and css. What am I missing and/or doing wrong and what else can I provide for you to better assist an answer?
<header class="banner navbar navbar-static-top navbar-default header page-section clear" role="banner">
<div class="wrapper clear">
<div class="logo">
<a href="<?php echo home_url(); ?>">
<!-- svg logo - toddmotto.com/mastering-svg-use-for-a-retina-web-fallbacks-with-png-script -->
n<img src="<?php echo get_template_directory_uri(); ?>/img/mj-logo.png" alt="Logo" class="logo-img">
</a>
</div>
<div class="navbar-header">
<button type="button" style="background-color:black" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-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>
<nav class="nav collapse navbar-collapse" role="navigation">
<?php html5blank_nav(); ?>
</nav>
</div>
</header>
.wrapper {
max-width:1280px;
width:95%;
margin:0 auto;
position:relative;
}
/* header */
.header {
top:0;
left:0;
right:0;
position: fixed;
background:#fff;
z-index: 1;
height: 0px;
overflow:hidden;
display:block;
opacity: 0;
transition: all .32s ease-in-out;
-moz-transition: all .32s ease-in-out;
-webkit-transition: all .32s ease-in-out;
}
.header.active {
opacity:1;
height: 80px;
}
.page-section {
width:100%;
height:100%;
margin:auto;
}
order of js links:
/wp-includes/js/jquery/jquery.js?ver=1.11.0
/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.2.
/wp-content/themes/michaeljerome.com/js/scripts.js?ver=1.0.0
https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js
Check if you included the javascript, the jquery javascript and the bootstrap javascript
bootstrap javascript
jquery javascript
this is usually the problem for not collapsing issues.
the jquery javascript must go first and then the bootstrap js file
/// this is your html markup
">
n/img/mj-logo.png" alt="Logo" class="logo-img">
Toggle navigation
if you want to add a logo or something else in your header put in a different column, is better not to mix things up.
try something like
<header>
<div class="container">
<div class="row">
<div class="col-md-4">
here goes whatever you want like your logo
</div>
<div class="col-md-8">
//here paste the navbar html code, not mixed with you header tag
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Brand</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active">Link</li>
<li>Link</li>
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
<li class="divider"></li>
<li>One more separated link</li>
</ul>
</li>
</ul>
<form class="navbar-form navbar-left" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<ul class="nav navbar-nav navbar-right">
<li>Link</li>
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
</div>
</div>
</div>
</header>
if the above doesn't work, take out any css you have in order to check if one of your css is overriding the navbar css.

Resources