Twitter Bootstrap fixed navbar transparent in chrome? - css

I've encountered most strange issue, and i can't seem to find anyone else that have encountered it.
I'm doing a site using Bootstrap 2.3.2, have a fixed top navbar that is suppose too have a white background. In safari, Explorer and Firefox it works flawlessly, however in newest Chrome, the navbar is completely transparent when scrolling down?
When scrolled to the top:
When scrolling down:
I haven't set "transparent" anywhere, my initial thoughts were along the line that z-index was incorrect or similar but why would it still be on top and transparent? (Also working in all other browsers as it should)
Another clue: there seem to be some flaw to the rendering with this particular setup, since in Chrome when scroll by a embedded Vimeo-video, the menu bar is seen in white over the embedded video.
HTML code as per below:
<nav>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="logo pull-left" href="#home"><img src="img/styleio.png" alt="Styleio"></a>
<div class="nav-collapse collapse">
<ul class="nav pull-right">
<li><a class="top-menu" href="#home">Home</a></li>
<li><a class="top-menu" href="#about">About</a></li>
<li><a class="top-menu" href="#offerings">Offerings</a></li>
<li><a class="top-menu" href="#features">Features</a></li>
<li><a class="top-menu" href="#contact">Contact</a></li>
<!--<a class="btn btn-primary btn-small red-bg pull right" href="#sign">Sign up</a> -->
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
</nav>
CSS code for the elements:
.navbar-fixed-top .navbar-inner,
.navbar-fixed-bottom .navbar-inner {
padding: 0px;
background-color:#ffffff;
}
.nav .navbar {
border:none;
background-color:#ffffff;
}
.nav {
padding-top:20px;
}
.navbar-fixed-top {
padding:0px;
margin:0px;
overflow:hidden;
}
.navbar-inner {
min-height: 90px;
background-color:#ffffff;
}
.navbar-inverse .nav > li > a {
border:none;
color: #666666;
font-weight:500;
}
.navbar-inverse .navbar-inner {
background: #ffffff;
filter: unquote("progid:DXImageTransform.Microsoft.gradient(enabled = false)");
}

Related

How do i remove this unwanted gap between my navabar and featured image? [duplicate]

This question already has answers here:
Mysterious whitespace in between Bootstrap2 Navbar and row underneath
(2 answers)
Closed 5 years ago.
I am creating a website with bootstrap, and I encountered a problem when I created a featured image with a parallax effect. It seems that something is creating a space between the navigation bar (Bootstrap) and the featured image.
.parallax {
background-image: url("../images/aboutHeader.jpg");
height: 100%;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.parallax h2 {
color: white;
font-size: 4em;
text-align: center;
padding-top: 100px;
}
<!-- NAVBAR
================================================== -->
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">
<img src="images/headerWhite.png" alt="Bird's Aerial Imaging LC" style="height:100%">
</a>
</div>
<div class="collapse navbar-collapse navbar-right" id="myNavbar">
<ul class="nav navbar-nav">
<li>Home</li>
<li class="active">About</li>
<li>Gallery</li>
<li>Services</li>
<li>Contact</li>
</ul>
</div>
</div>
</nav>
<!-- FEATURED IMAGE =============================================================== -->
<section style="height:250px;">
<div class="parallax">
<h2>About Us</h2>
</div>
</section>
What I understood from you that you mean the white vertical space between the parallax div and the navbar and my answer will depend on that, if your problem is different please let me know.
Your solution is all about removing:
1) The margin property from the "h2":
.parallax h2 {
margin-top: 0;
}
2) The padding property from the "navbar":
.navbar {
padding-bottom: 0;
}
Hope it works with you!
You can add position:absolute; top:0; to your section tag. That will definitely remove the space...
It could also be because of default margin or padding around the section. Try to add margin:0; padding:0; to that

Bootstrap 3 CSS - fixed navbar causes a lot of white space on short pages

Following this example from the official documentation, i noticed that on pages who are going to be < 2000px in height, i will have a lot of white space below the footer.
I can't specify the height of the footer as per this example (it might increase dynamically) so i guess i can't stick it to the footer?
How to work around this?
Use the Boostrap's sticky footer, and for the height of Footer, use this jquery, it checks height of footer and adds it to the html tag.
It runs on page load as well as on Window.resize event, so it works great for Responsive projects.
$(document).ready(function(){
$(window).resize(function(){
$("html").css("padding-bottom",$(".footer").outerHeight())
}),
$("html").css("padding-bottom",$(".footer").outerHeight()
);
});
What actually makes the footer stick to the bottom of the page in the example you are linking to in your comment is not the footer height, but the following CSS rules:
.footer {
position: absolute;
bottom: 0;
}
You can see this for yourself if you view the footer through your browser's developer tools and disable the height CSS rule, the footer will continue to be at the bottom of the page.
As far as the body margin is concerned, since your footer does not have a fixed height the only way you can set this is use Javascript to measure the footer and set the body margin on document.ready. See the attached example:
$(document).ready(function(){
var footerHeight = $('.footer').height();
$('body').css('margin-bottom', footerHeight);
});
/* Sticky footer styles
-------------------------------------------------- */
html {
position: relative;
min-height: 100%;
}
body {
/* Margin bottom by footer height */
margin-bottom: 60px;
}
.footer {
position: absolute;
bottom: 0;
width: 100%;
/* Set the fixed height of the footer here */
height: 60px;
background-color: #f5f5f5;
}
/* Custom page CSS
-------------------------------------------------- */
/* Not required for template or sticky footer method. */
body > .container {
padding: 60px 15px 0;
}
.container .text-muted {
margin: 20px 0;
}
.footer > .container {
padding-right: 15px;
padding-left: 15px;
}
code {
font-size: 80%;
}
<link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://getbootstrap.com/dist/js/bootstrap.min.js"></script>
<!-- Fixed navbar -->
<nav class="navbar navbar-default navbar-fixed-top">
<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">
<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="#">Project name</a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>About</li>
<li>Contact</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 class="dropdown-header">Nav header</li>
<li>Separated link</li>
<li>One more separated link</li>
</ul>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<!-- Begin page content -->
<div class="container">
<div class="page-header">
<h1>Sticky footer with fixed navbar</h1>
</div>
<p class="lead">Pin a fixed-height footer to the bottom of the viewport in desktop browsers with this custom HTML and CSS. A fixed navbar has been added with <code>padding-top: 60px;</code> on the <code>body > .container</code>.</p>
<p>Back to the default sticky footer minus the navbar.</p>
</div>
<footer class="footer">
<div class="container">
<p class="text-muted">Place sticky footer content here.</p>
</div>
</footer>

How to make horizontal glyphs on navbar to show as vertical menu

I want to show the glyphs as in example A for desktop monitors and as in example B for mobile when the menu is extended. (The code is the same in both examples, except for the css).
Example A: http://jsfiddle.net/bs773m84/4/
<div class="container">
<nav class="header-nav-wrapper container-nav-menu navbar navbar-default white-back">
<div class="container-fluid">
<div class="navbar-header">
<a alt="" rel="home" href="google.com">
<img class="logo" src="http://icons.iconarchive.com/icons/cornmanthe3rd/plex-android/48/app-drawer-icon.png"/>
</a>
<button data-target="#social-menu" data-toggle="collapse" class="navbar-toggle collapsed" type="button">
<span class="sr-only"><?php _e('Toggle navigation menu','justmakeit');?></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="col-sm-11 content">
<div class="container-fluid">
<div class="hidden-xs col-sm-6 blue-light-back"><span>Brand</span>
</div>
<div class="col-xs-12 col-sm-4 col-sm-push-4 col-md-push-4 red-dark-back">
<div id="social-menu" class="collapse navbar-collapse">
<ul class="menu nav navbar-nav navbar-default white-back">
<li class="facebook">
<a href="http://facebook.com" target="_blank">
<span class="glyphicon glyphicon-play-circle"></span><span class="social-name">facebook</span>
</a>
</li>
<li class="twitter">
<a href="http://twitter.com" target="_blank">
<span class="glyphicon glyphicon-download"></span><span class="social-name">twitter</span>
</a>
</li>
<li class="google-plus">
<a href="http://plus.google.com" target="_blank">
<span class="glyphicon glyphicon-download"></span><span class="social-name">google+</span>
</a>
</li>
<li class="pinterest">
<a href="http://pinterest.com" target="_blank">
<span class="glyphicon glyphicon-download"></span><span class="social-name">pinterest</span>
</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</nav>
</div>
Example A css:
#social-menu li{
display: inline-block;
padding: 0px;
}
#social-menu li a{
padding: 0px;
}
#social-menu .social-name{
display: block;
height: 1.4375em;
overflow: hidden;
text-indent: 100%;
transition: all 0.3s ease 0s;
white-space: nowrap;
width: 1.4375em;
}
Example B: http://jsfiddle.net/77m94xf4/4/
Html is the same as in Example A.
Example B css: No.
To do this you can use #media Query and set your css attribute for each size.
for Example :
#media screen and (max-width: 300px)
{
add your css for mobile
}
#media screen and (min-width: 800px)
{
add your css for desctop
}
by #media Query you can set css for each devices. eg:mobile,tablet,desktop.
Learn more about #media query
I added #media Query to revert CSS of the menu items for mobile.
#media screen and (min-width: 1px) and (max-width: 767px){
#social-menu li{
display:block
}
#social-menu .social-name{
display: inline;
height: none;
overflow: none;
text-indent: none;
white-space: none;
width: none;
}
}

Center content in responsive bootstrap navbar

I'm having trouble centering my content in the bootstrap navbar. I'm using bootstrap 3. I've read many posts, but the CSS or methods used will not work with my code! I'm really frustrated, so this is like my last option. Any help would be appreciated!
<!DOCTYPE html>
<html>
<head>
<title>Navigation</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="css/style.css" rel="stylesheet" media="screen">
</head>
<body>
<div class="container">
<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=".navbar-ex1-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>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav">
<li>Link</li>
<li>Link</li>
<li>Link</li>
<li>Link</li>
<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>Separated link</li>
<li>One more separated link</li>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</nav>
<h1>Home</h1>
</div>
<!--JAVASCRIPT-->
<script src="js/jquery-1.10.2.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
https://jsfiddle.net/amk07fb3/
I think this is what you are looking for. You need to remove the float: left from the inner nav to center it and make it a inline-block.
.navbar .navbar-nav {
display: inline-block;
float: none;
vertical-align: top;
}
.navbar .navbar-collapse {
text-align: center;
}
http://jsfiddle.net/bdd9U/2/
Edit: if you only want this effect to happen when the nav isn't collapsed surround it in the appropriate media query.
#media (min-width: 768px) {
.navbar .navbar-nav {
display: inline-block;
float: none;
vertical-align: top;
}
.navbar .navbar-collapse {
text-align: center;
}
}
http://jsfiddle.net/bdd9U/3/
The original post was asking how to center the collapsed navbar. To center elements on the normal navbar, try this:
.navbar-nav {
float:none;
margin:0 auto;
display: block;
text-align: center;
}
.navbar-nav > li {
display: inline-block;
float:none;
}
There's another way to do this for layouts that doesn't have to put the navbar inside the container, and which doesn't require any CSS or Bootstrap overrides.
Simply place a div with the Bootstrap container class around the navbar. This will center the links inside the navbar:
<nav class="navbar navbar-default">
<!-- here's where you put the container tag -->
<div class="container">
<div class="navbar-header">
<!-- header and collapsed icon here -->
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<!-- links here -->
</ul>
</div>
</div> <!-- close the container tag -->
</nav> <!-- close the nav tag -->
If you want the then align body content to the center navbar, you also put that body content in the Bootstrap container tag.
<div class="container">
<! -- body content here -->
</div>
Not everyone can use this type of layout (some people need to nest the navbar itself inside the container). Nonetheless, if you can do it, it's an easy way to get your navbar links and body centered.
You can see the results in this fullpage JSFiddle:
http://jsfiddle.net/bdd9U/231/embedded/result/
Source:
http://jsfiddle.net/bdd9U/229/
For Bootstrap 4:
Just use
<ul class="navbar-nav mx-auto">
mx-auto will do the job
Bootstrap 5 (Update 2021)
The Navbar is still flexbox based in Bootstrap 5 and centering content works the same as it did with Bootstrap 4. Examples
Bootstrap 4
Centering Navbar content is easier is Bootstrap 4, and you can see many centering scenarios explained here: https://stackoverflow.com/a/20362024/171456
Bootstrap 3
Another scenario that doesn't seem to have been answered yet is centering both the brand and navbar links. Here's a solution..
.navbar .navbar-header,
.navbar-collapse {
float:none;
display:inline-block;
vertical-align: top;
}
#media (max-width: 768px) {
.navbar-collapse {
display: block;
}
}
http://codeply.com/go/1lrdvNH9GI
Also see:
Bootstrap NavBar with left, center or right aligned items
This code worked for me
.navbar .navbar-nav {
display: inline-block;
float: none;
}
.navbar .navbar-collapse {
text-align: center;
}
from the bootstrap official site (and, almost, like Eric S. Bullington said.
https://getbootstrap.com/components/#navbar-default
the example navbar looks like:
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
...etc
to center the nav, that what i've done:
<div class="container-fluid" id="nav_center">
css:
#media (min-width:768px) { /* don't break navbar on small screen */
#nav_center {
width: 700px /* need to found your width according to your entry*/
}
}
work with class="container" and navbar-right or left, and of course you can replace id by class. :D
Seems like all these answers involve custom css on top of bootstrap. The answer I am providing utilizes only bootstrap so I hope it comes to use for those that want to limit customizations.
This was tested with Bootstrap V3.3.7
<footer class="navbar-default navbar-fixed-bottom">
<div class="container-fluid">
<div class="row">
<div class="col-xs-offset-5 col-xs-2 text-center">
<p>I am centered text<p>
</div>
<div class="col-xs-5"></div>
</div>
</div>
</footer>
this should work
.navbar-nav {
position: absolute;
left: 50%;
transform: translatex(-50%);
}
Use following html
<link rel="stylesheet" href="app/components/directives/navBar/navBar.scss"/>
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<!-- Collect the nav links, forms, and other content for toggling -->
<ul class="nav navbar-nav">
<li><h5>Home</h5></li>
<li>|</li>
<li><h5>About</h5></li>
<li>|</li>
<li><h5>Contacts</h5></li>
<li>|</li>
<li><h5>Cart</h5></li>
</ul>
</div><!-- /.container-fluid -->
</nav>
And css
.navbar-nav {
width: 100%;
text-align: center;
}
.navbar-nav > li {
float: none;
display: inline-block;
}
.navbar-default {
background-color: white;
border-color: white;
}
.navbar-default .navbar-nav>.active>a, .navbar-default .navbar-nav>.active>a:hover, .navbar-default .navbar-nav>.active>a:focus{
background-color:white;
}
Modify according to your needs
V4 of BootStrap is adding Center (justify-content-center) and Right Alignment (justify-content-end) as per: https://v4-alpha.getbootstrap.com/components/navs/#horizontal-alignment
<ul class="nav justify-content-center">
<li class="nav-item">
<a class="nav-link active" href="#">Active</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
it because it apply flex. you can use this code
#media (min-width: 992px){
.navbar-expand-lg .navbar-collapse {
display: -ms-flexbox!important;
display: flex!important;
-ms-flex-preferred-size: auto;
flex-basis: auto;
justify-content: center;
}
in my case it workded correctly.

How do i shift the text in twitter bootstrap navbar to center?

I integrated twitter bootstrap navbar into my asp.net project. However, I'm trying to align my bootstrap text into the center. Here is my source code for my navbar
<div id="twitterbootstrap">
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="#">iPolice</a>
<div class="nav-collapse">
<ul class="nav">
<li class="divider-vertical"></li>
<li>Home</li>
<li class="divider-vertical"></li>
<li>Login</li>
<li class="divider-vertical"></li>
<li>Contact</li>
</ul>
</div>
</div>
</div>
</div>
</div>
This is the image of my bootstrap
Then i added this twitterbootstrap css inside to attempt and shift the ipolice, home, contact and login into the center
#twitterbootstrap {
position:absolute;
text-align:center;
}
which didnt work. I visited this link and tried but still wasn't able to do it. May i ask how do i align my text into the center?
Depending on where you want the Brand link to appear, here are two possiblities
http://jsfiddle.net/panchroma/cW9sA/
or
http://jsfiddle.net/panchroma/GWMnF/
EDIT: A third variation where the iPolice brand link is always centered, even at narrow viewports
http://jsfiddle.net/panchroma/F5x5Z/
Note that in the second example I've added a copy of the brand link into the main menu, and used the utility classes of .hidden-desktop and .visible-desktop to fine tune how this is displayed at different viewports
Important CSS is
#twitterbootstrap .navbar .nav,
#twitterbootstrap .navbar .nav > li {
float:none;
display:inline-block;
*display:inline; /* ie7 fix */
*zoom:1; /* hasLayout ie7 trigger */
vertical-align: top;
}
#twitterbootstrap .navbar-inner {
text-align:center;
}
Some of this CSS is based on an answer from Andres Ilich
Good luck!

Resources