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

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!

Related

Why is this text running outside of the li element?

Hope somebody can see what's going on with this, it's got me beat.
I have an issue with the tag text elements inside a drop-down menu extending beyond the li element for the mobile version of the navigation in the footer. The li element has a width restriction (is shaded orange to see clearly), you can see the problem on this page when browser is mobile width wide https://www.mcveaghfleming.co.nz/nav-issues.html There are some long link names and instead of flowing under the line above they are extending past the end of the li element.
Here's the relevent html
<div class="footer">
<div class="blockfooter">
<div class="row ft-low-nav ">
<style>
.foot-mobile-on .dropdown-menu li{float:left; width:100%; background:orange; word-wrap: break-word !important;}
.foot-mobile-on .dropdown-menu li,
.foot-mobile-on .dropdown-menu li a{display:inline-block;}
</style>
<span class="foot-mobile-on">
<div class="col-md-12">
<div id="navbar" class="navbar-collapse collapse dropdown">
<ul class="nav navbar-nav" >
<li><a href="#" class="dropdown-toggle make-b" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Business & Corporate <span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li class="make-b">Business & Corporate </li>
<li>Anti-Money Laundering and Countering Financing of Terrorism Act 2009 Compliance and Advice
</li>
</ul>
</li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
</span>
<!-- end-->
</div>
</div>
</div>
<!--end-->
Be sure to set position:relative or anything different than the static default to the UL.
Adding up, this is to prevent the 100% width to be referring to an upper parent. My guess is that a lack of position declaration on the parent is scaling up the DOM to the entire body width. A quick inspect on the code should give you a hint about this, but is hard without seeing the actual code in action.

Twitter Bootstrap navbar elements not aligned as desired

I am new to bootstrap and am trying to make simple menu/nav.
I am trying to make contents of the menu centered along with the brand. Also when I make the screen smaller the menu items move under the brand. How can I make it so that it doesn't? There seems to be enough space in the nav to not make the items move under.
Note: I have not written any CSS for this.
https://jsfiddle.net/b9smvjn0/
HTML:
<div class="navbar navbar-default" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#account-options" 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>
<h4 class="navbar-brand">Image Box</h4>
</div><!--end navbar header-->
<!--togglable menu items-->
<div class="collapse navbar-collapse" id="account-options">
<ul class="nav navbar-nav">
<li>Upload Photo</li>
<li>Deactivate Account</li>
<li>Activate Account</li>
<li>Delete Account</li>
<li>Log Out</li>
</ul>
</div><!--end toggle-->
</div><!--end container-->
</div><!--end navigation-->
I think it's because your h4 element inside the navbar-header. It's adding an extra margin on top and bottom, this is why it doesn't align.
.navbar-header h4 {margin:0;}
I removed it in your fiddle and it's working.
https://jsfiddle.net/b9smvjn0/1/
Is this what you want?
Edit
Hopefully this is what you are looking for.
Note: This is using custom css, so if you plan to stick with pure bootstrap, you'll to do in another way.
I added a div around the brand and the navbar so, we can center both elements.
Also i reduced the amount of padding on the a tag inside the navbar. This is necessary because of the amount of menu items you have.
Then i just used the technique of text-align:center; margin:0 auto; on the container div. It's inside a media(min-width:768); because when it get smaller the layout change, so we get it back to original position.
This the updated fiddle: https://jsfiddle.net/b9smvjn0/3/
To remove the extra space, you can remove the margin for the <h4>. And for centering all the <nav> content, or keeping it on the straight line, use these:
white-space: nowrap;
overflow: hidden;
Fiddle: https://jsfiddle.net/oLmnjh3p/

bootstrap navbar inherit a gradient color of parent

I'm trying to figure out how to change the background color of a bootstrap nav bar to match the background of the element, in this case the body tag, behind it. The effect I am wanting is similar to 'background-color:transparent' but I don't want it transparent; I want the page to flow behind it still as you scroll down. I also do not want it to inherit the parent background as it is a linear-gradient. What I am looking to do is set the background of the whole nav bar as the current color behind the nav bar on the parent element behind it.
Since that didn't come out very clear, I set up an example in jsfiddle: https://jsfiddle.net/y1Lev5o6/2/
Using bootstrap resources, here is the html on the fiddle
<body style="background-image:-webkit-linear-gradient(top,#023322,#ffffff); background-repeat:no-repeat; height:1000px;">
<div class="navbar navbar-inverse navbar-fixed-top" style="background-image:none; background-color:transparent;">
<div class=" container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav" style="color:white;">
<li>Home</li>
<li>About</li>
<li>Contact</li>
</ul>
</div>
</div>
</div>
<div class="container body-content">
<div style="background-color: white; height: 100px;margin-top:200px;">
I don't want to see white in my nav bar</div>
<footer style="padding-top:200px;">
<p style="color:white;">© my website</p>
</footer>
</div>
If you scroll down on the results of the fiddle I think it is obvious of what I am trying to accomplish, or in this case prevent. I want all my page elements to flow behind my nav bar, but want the nav bar to pick up the color directly behind it on the body tag.
With the help of a little javascript:
$(document).ready(function(){
$(window).scroll(function(e){
var scr = $(window).scrollTop();
$('.navbar').css('background-position', '0px -'+ scr+'px');
});
});
and CSS:
.navbar{
background-image:-webkit-linear-gradient(top,#023322,#ffffff);
background-repeat:no-repeat;
background-position:top;
background-size:auto 1000px;
}
See this updated fiddle
Essentially what's going on here is the .navbar gets the same gradient backgorund, and it's position is changed/moved with the window scrolling.

css and bootstrap errors with Firefox and Explorer

I have this site that use bootstrap.
It is developed using Chrome for tests (my negligence)
I can't understand why in firefox and i.e. this works very bad!! Can someone give me some directions of what I have to change in my css to have the website compatible with every browser?
for example:
the menu on top is invisible (no background image) and isn't fixed
titles like 'Presentazioni' isn't in the middle of the page
images in the 'Presentazioni' and 'La Famiglia' paragraph are too big --> resolved putting instead of
<img src="..." width="100px;">
<img src="..." style="width: 100px;">
all text isn't in the middle of the page
the menu on bottom is completely different
Is there any tool I can use to find css properties that are incompatible with firefox and ie?
Your main problem is in your themes/css/style.css file. Line 23:
h1{padding: 0 0 44px; font-weight: 200;font-size: 64px;line-height: 56px;color: #464646;margin: 0;font-family: 'font-family: 'Special Elite';text-rendering: optimizelegibility; text-transform: uppercase;}
font-family is repeated twice and you have a single quote before the second font-family, thats commenting the whole code. Correct that and let's see what happen, I can't try it.
Anyway, you should replace your navbar code with this one:
<div class="navbar navbar-fixed-top" id="headerSection">
<div class="navbar-inner" style="background: url(imm/parquet.jpg);background-color: grey; background-repeat: no-repeat; border-bottom: 1px solid #dedede; padding: 8px 0 0;">
<div class="container">
<button type="button" class="btn btn-navbar" data-target=".nav-collapse" data-toggle="collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<!-- h1 class="brand cntr">TEVAD</h1-->
<div class="nav-collapse collapse" style="height: 0px;">
<ul class="nav">
<li class="active">Home</li>
<li>Presentazioni</li>
<li>La Famiglia</li>
<li>Gallery</li>
<li>Video</li>
<li>Contatti</li>
</ul>
</div>
</div>
</div>
</div>
Try to remove the inline styles and define them in the css file. Do not fix the navbar from the css file, use the .navbar-fixed-top class instead. Read the bootstrap documentation, you are not using the correct structure nor the correct classes: Bootstrap navbar.

Twitter Bootstrap fixed navbar transparent in chrome?

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)");
}

Resources