Bootstrap collapse nav not working in custom wordpress theme - css

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.

Related

Bootstrap + Mobile Menu Overlay

I have a page that uses Bootstrap 3. In this page, I have a navbar that's defined like the following:
<nav class="navbar" style="background-color:orange;">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar" style="color:#000 !important;">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar" style="color:#000;"></span>
<span class="icon-bar" style="color:#000;"></span>
<span class="icon-bar" style="color:#000;"></span>
</button>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="/home" class="dropdown-toggle navbar-dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
Home <span class="caret"></span></a>
<ul class="dropdown-menu">
<li>help</li>
<li>contact</li>
</ul>
</li>
</ul>
<div class="navbar-right">
<div class="visible-xs">
<div class="row">
<div class="col-xs-6">
2016
<ul class="dropdown-menu dropdown-menu-right">
<li>Q1</li>
<li>Q2</li>
<li>Q3</li>
<li>Q4</li>
</ul>
</div>
<div class="col-xs-6">
2017
<ul class="dropdown-menu dropdown-menu-right">
<li>Q1</li>
<li>Q2</li>
<li>Q3</li>
<li>Q4</li>
</ul>
</div>
</div>
</div>
<div class="hidden-xs">
<ul class="nav navbar-nav">
<li>
2016
<ul class="dropdown-menu dropdown-menu-right">
<li>Q1</li>
<li>Q2</li>
<li>Q3</li>
<li>Q4</li>
</ul>
</li>
<li>
2017
<ul class="dropdown-menu dropdown-menu-right">
<li>Q1</li>
<li>Q2</li>
<li>Q3</li>
<li>Q4</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</div>
</nav>
The navbar looks and works like I want on bigger screens. But on mobile, it doesn't work correctly. As you can see in this Bootply, the nav menu pushes the main content (the Lorem Ipsum) down. However, I want the nav menu to appear on top of the content, so that the mobile nav appears on top of the Lorem Ipsum stuff. What am I doing wrong?
Do you want like this:
http://www.bootply.com/9OB6nhtg4i#
#media (max-width:768px) {
.navbar {
position: absolute;
}
}
Add this css and try.
U need to use navbar-fixed-top class and set top padding for main block:
main {
padding-top: 60px;
}
http://www.bootply.com/aROSWOLDZY

Keep search on navbar when collapsed

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

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/

Change opacity bootstrap navbar

I'm trying to make my navbar semitransparent on this code but I'm not able to do it:
<nav class="navbar navbar-default navbar-fixed-top transparent" >
<div class="container">
<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">Home <span class="sr-only">(current)</span></li>
<li>Searches</li>
<li>Contact</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 class="dropdown">
Legal <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Terms</li>
<li>DMCA</li>
<li>RTA</li>
<li class="divider"></li>
<li>Contact</li>
Try this in your code, it worked for me -
give an id to the nav
like this-
<nav class="navbar navbar-default navbar-fixed-top transparent" id="nav1">
Then apply this in your css-
#nav1
{
background-color:#F00; /*whichever you want*/
opacity: 0.5;
filter:(opacity=50);
}
in your bootstrap.css find the navbar you are using, for example, if you're using the default navbar search for .navbar-default or .navbar-inverted as per your case and set the opacity simply using the CSS opacity command.
Did the job for me.
It would be nice to see the orginal CSS.
Paste the css code that shows the opacity.
The way I see your problem I think you did not write the path correct enough so it doesn't overwrite the original css from bootstrap.
<div id="wrapper">
<div class="container">
<div class="nav">
<p>tessssssssssssssst</p>
<div>
</div>
</div>
#wrapper .container .nav{
background-color: red;
opacity: 0.3;
}
#wrapper .nav {
opacity: 1.0;
}
http://jsfiddle.net/7h4hrvhu/

Rounded radius in twitter boostrap navbar

There seems to be an odd border-radius of 4px on my navbar in my rails app using bootsrap 3 and I cant seem to get rid of it.
I've tried
.navbar { border-radius: none}
I can't even edit the bootstrap css because I cant seem to find it. Any eloquent work arounds?
Here the HTML
<nav class="navbar navbar-default" role="navigation">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" 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>
<%= link_to "app", root_path , class: "navbar-brand" %>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
</li>
</ul>
<ul class="nav navbar-nav nav-pills navbar-right">
<li class="dropdown">
Dropdown <b class="caret"> </b>
<ul class="dropdown-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 -->
</nav>
It's because none isn't a valid value for border-radius. From the specs, the values of border-radius are lengths or percentages. See the documentation.
You want the following:
.navbar { border-radius: 0; }
EXAMPLE

Resources