Bootstrap Center Navbar Items - css

I know I can push navbar items to the left and right, but how would I center them?
text-align:center;
doesn't work nor any of the other things I thought of.

You will need to modify some CSS rules for Navbar component. So add a class center to nav.navbar and the following rules:
.navbar.center .navbar-inner {
text-align: center;
}
.navbar.center .navbar-inner .nav {
display:inline-block;
float: none;
}
Working demo (Bootstrap 3.3.7)

To extend upon the selected answer, adding vertical align top will prevent the space from appearing under the nav items.
.navbar.center .navbar-inner {
text-align: center;
}
.navbar.center .navbar-inner .nav {
display:inline-block;
float: none;
vertical-align: top;
}
Demo

I had similar problem. What worked for me is adding rule 'justify-content' like this:
CSS:
.navbar-expand-lg .navbar-collapse {
display: flex!important;
justify-content: space-around;
flex-basis: auto;
}
HTML:
<nav id="hamburger" class="navbar sticky-top navbar-expand-lg navbar-light">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
<div class="navbar-nav center">
<div><a class="nav-item nav-link active" href="#">
Start <span class="sr-only">(current)</span></a>
</div>
<div><a class="nav-item nav-link" href="#">Portfolio</a></div>
<div><a class="nav-item nav-link" href="#">Blog</a></div>
<div><a class="nav-item nav-link" href="#">O mnie</a></div>
<div><a class="nav-item nav-link" href="#">Kontakt</a></div>
</div>
</div>
</nav>

Use text-center or mx-auto or container-fluid or use flexbox technique, flex justify-center
You could use this hack text-center (this does not only apply for text)
Or use the exact boostrap class mx-auto
example
class="text-center" or class="mx-auto"
in context
<div class="btn-group text-center"> or <div class="btn-group mx-auto">
TRY NOT TO USE inline styles (bad practice)
<div class="btn-group" style="margin:0 auto">
References here:
text-center =>
https://getbootstrap.com/docs/4.0/utilities/text/
mx-auto => https://getbootstrap.com/docs/4.0/utilities/spacing/#horizontal-centering

You can use
text-align:center;
to a wrapper element to center its childs, but only if the childs have
display: inline;
/* or */
display: inline-block;
Another option, if you know the width of the element you want to center, is
display: block;
width: /* something */;
margin: 0 auto;

Related

Flexbox Bootstrap 4 Navbar with additional content vertical aligned and always visible

The challenge: create a nav bar that has a brand logo on the left with the navbar-collapse menu and some other call to action/link above it on the right, and have them all vertically positioned.
Seems straight forward, until you want the mobile to look like this:
How can we achieve this with good responsive css (no negative margins/absolute positioning techniques) and no JS?
I've only come up with the option of printing the Phone number twice on the page, and hiding/showing for various screen sizes:
<header>
<div class="content-above-navbar container">
<div class="row d-md-none flex-row-reverse">
<div class="col-auto ml-3"><span class="navbar-text">800-BS4-WEBS</span></div>
<div class="col-auto p-0"><span class="navbar-text">Contact Us</span></div>
</div>
</div>
<nav class="navbar navbar-expand-md navbar-light bg-light">
<div class="container">
<a class="navbar-brand" href="Bootstrap 4 Navbar">Bootstrap 4 Navbar</a>
<button class="navbar-toggler collapsed" type="button" data-toggle="collapse" data-target="#all-pages-176" aria-controls="all-pages-176" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button>
<div id="all-pages-176" class="navbar-collapse has-content-above collapse">
<div class="content-above-nav-menu">
<div class="float-md-right ml-md-3 d-none d-md-block"><span class="navbar-text">800-BS4-WEBS</span></div>
<div class="float-md-right d-none d-md-block"><span class="navbar-text">Contact Us</span></div>
</div>
<ul id="menu-all-pages" class="navbar-nav ml-auto">
<li id="menu-item-1700" class="nav-item active">Sample Page</li>
<li id="menu-item-1701" class="nav-item">Page Markup And Formatting</li>
<li id="menu-item-1702" class="nav-item">Page Image Alignment</li>
<li id="menu-item-1705" class="nav-item">Level 1</li>
</ul>
</div>
</div>
</nav>
</header>
There's a tiny bit of custom css to make the non-menu info stack up a row and move to the right. See the fiddle link:
Here's a Fiddle
Other markups work for one screen size, but not the other.
Is anybody seeing a solution to this that can be achieved w/ a relatively flat markup?
Echoing Raphael's comment to your question, I'm not entirely sure if the issue could be solved using Bootstrap's styles (other than with duplication of content, as you've shown).
Ignoring Bootstrap, if you only need to support IE11+ then CSS Grid can be used to achieve the layout you've described. I don't have enough experience with Bootstrap to know how well this solution would play with Bootstrap's styles, but here's a barebones example of your layout implemented with pure CSS grids (supporting IE would require adding additional styles that I left out for brevity):
.header {
margin: 1em;
padding: 1em;
display: grid;
grid-template-rows: auto auto;
grid-template-columns: 1fr auto;
grid-template-areas:
"c c"
"l t"
}
.header__logo {
grid-area: l;
}
.header__contact {
grid-area: c;
justify-self: end;
}
.header__menu {
display: none;
}
.header__toggle {
grid-area: t;
margin-left: 1em;
align-self: center;
}
#media (min-width:768px) {
.header {
grid-template-rows: auto auto;
grid-template-columns: auto 1fr;
grid-template-areas:
"l c"
"l m"
}
.header__toggle {
display: none;
}
.header__contact {
align-self: center;
}
.header__menu {
display: flex;
grid-area: m;
align-self: center;
justify-self: end;
}
}
/* debug styles */
.header {
border: 1px solid red;
}
.header > * {
outline: 1px dashed #cf0;
}
<div class="header">
<img src="http://via.placeholder.com/200x80&text=Brand+Logo"/>
<div class="header__contact">
Contact Us 800-BS4-WEBS
</div>
<button class="header__toggle">=</button>
<div class="header__menu">
Sample Page
Another Page
</div>
</div>
It can be done with the Bootstrap 4 grid and utility classes...
Demo: https://www.codeply.com/go/CBsBPCE4oV
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container">
<div class="row w-100 no-gutters d-lg-block d-flex flex-wrap justify-content-between">
<a class="navbar-brand col-lg-3 col-6 py-lg-3 order-lg-1 order-2 float-left d-block h-100" href="Bootstrap 4 Navbar">
Logo
</a>
<div class="navbar-text col-lg-6 col-12 order-lg-2 order-1 text-right float-right align-self-end">800-BS4-WEBS</div>
<button class="navbar-toggler collapsed float-right order-3" type="button" data-toggle="collapse" data-target="#all-pages-176" aria-controls="all-pages-176" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div id="all-pages-176" class="navbar-collapse collapse float-right col-lg-8 order-4">
<ul id="menu-all-pages" class="navbar-nav ml-auto justify-content-lg-end w-100">
<li id="menu-item-1700" class="nav-item active">Sample Page</li>
<li id="menu-item-1701" class="nav-item">Page Markup And Formatting</li>
<li id="menu-item-1702" class="nav-item">Page Image Alignment</li>
<li id="menu-item-1705" class="nav-item">Level 1</li>
</ul>
</div>
</div>
</div>
</nav>

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

Material Design Lite and Bootstrap Sticky Footer

I am building a site where I use the Bootstrap Sticky Footer and Navbar. However, with Google's recent release of the Material Design Lite library, I want to use the cards for a portion of my site. However, as soon as I include the MDL library (just the CSS, no other changes), my sticky footer does something odd. The footer is set to the bottom of the viewport (no matter the height of that window) but then it just sticks there. If I scroll up, it scrolls up as well.
When I actually inspect the footer, body, etc., I see nothing that is affecting the layout from the material design CSS. Something obviously is, but I'm fairly stuck on what it might be. (To see it work, remove the reference to the material-lite.css. Currently it is broken within the snippet.)
html {
position: relative;
min-height: 100%;
}
body {
margin-bottom: 60px;
padding-bottom: 20px;
}
footer {
position: absolute;
bottom: 0;
width: 100%;
height: 60px;
color: white;
background-color: black;
}
#footer-content {
margin: 20px 0;
}
<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.5/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://storage.googleapis.com/code.getmdl.io/1.0.0/material.min.css" />
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<a asp-controller="Home" asp-action="Index" class="navbar-brand">
<i class="fa fa-globe fa-lg visible-sm visible-xs"></i>
<i class="fa fa-globe fa-3x hidden-sm hidden-xs"></i>
</a>
<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 main-links">
<li><a asp-controller="Home" asp-action="Index">Home</a>
</li>
<li><a asp-controller="Home" asp-action="About">About</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container">
<img src="http://placekitten.com/300/450" />
<br/>
<img src="http://placekitten.com/300/450" />
<br/>
</div>
<footer>
<div class="container">
<div id="footer-content" class="pull-right">
My Footer
</div>
</div>
</footer>
I found the correct solution to keeping footer stuck to bottom even if the content of a new tab is a different height.
https://github.com/google/material-design-lite/issues/913
This js fiddle specifically had useful html and css.
http://jsfiddle.net/eggbox/gk7u32b6/
In short add this to your html above the footer
<style>
.mdl-layout__content {
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-flow: column nowrap;
-ms-flex-flow: column nowrap;
flex-flow: column nowrap;
}
.mdl-layout__content > *:not(.mdl-layout-spacer) {
-webkit-flex: none;
-ms-flex: none;
flex: none;
}
</style>
<div class="mdl-layout-spacer"></div>
<footer class="mdl-mini-footer">
<div class="mdl-mini-footer--middle-section">
<div class="mdl-logo">Title</div>
<ul class="mdl-mini-footer--link-list">
<li>Help</li>
<li>Privacy & Terms</li>
</ul>
</div>
</footer>
This should fix your problem. See plunker
html {
height: auto;
}

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

Bootstrap 3 Navbar with Logo

I want to use the Bootstrap 3 default navbar with an image logo instead of text branding. What's the proper way of doing this without causing any issues with different screen sizes? I assume this a common requirement, but I haven't yet seen a good code sample. A key requirement other than having acceptable display on all screen sizes is the menu collapsibility on smaller screens.
I tried just putting an IMG tag inside the A tag that has the navbar-brand class, but that caused the menu not to function properly on my android phone. I also tried increasing the height of the navbar class, but that screwed things up even more.
By the way, my logo image is larger than the height of the navbar.
Why is everyone trying to do it the hard way? Sure, some of these approaches will work, but they're more complicated than is necessary.
OK, first - you need an image that will fit within your navbar. You can adjust your image via css height attribute (allowing width to scale) or you can just use an appropriately sized image. Whatever you decide to do - the way this looks will depend on how well you size your image.
For some reason, everyone wants to stick the image inside of an anchor with navbar-brand, and this isn't necessary. navbar-brand applies text styles that aren't necessary to an image, as well as the navbar-left class (just like pull-left, but for use in a navbar). All you really need is to add navbar-left.
<img src="/path/to/image.png">
You can even follow this with a navbar-brand item, which will appear to the right of the image.
<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>
<a class="navbar-brand" rel="home" href="#" title="Buy Sell Rent Everyting">
<img style="max-width:100px; margin-top: -7px;"
src="/img/transparent-white-logo.png">
</a>
</div>
COMPLETE DEMO WITH MANY EXAMPLES
IMPORTANT UPDATE: 12/21/15
There is currently a bug in Mozilla I discovered that breaks the navbar on certain browser widths with MANY DEMOS ON THIS PAGE. Basically the mozilla bug is including the left and right padding on the navbar brand link as part of the image width. However, this can be fixed easily and I've tested this out and I fairly sure it's the most stable working example on this page. It will resize automatically and works on all browsers.
Just add this to your css and use navbar-brand the same way you would .img-responsive. Your logo will automatically fit
.navbar-brand {
padding: 0px; /* firefox bug fix */
}
.navbar-brand>img {
height: 100%;
padding: 15px; /* firefox bug fix */
width: auto;
}
Another option is to use a background image. Use an image of any size and then just set the desired width:
.navbar-brand {
background: url(http://disputebills.com/site/uploads/2015/10/dispute.png) center / contain no-repeat;
width: 200px;
}
ORIGINAL ANSWER BELOW (for reference only)
People seem to forget about object-fit a lot. Personally I think it's the easiest one to work with because the image automatically adjusts to the menu size. If you just use object fit on the image it will auto resize to the menus height.
.navbar-brand > img {
max-height: 100%;
height: 100%;
-o-object-fit: contain;
object-fit: contain;
}
It was pointed out that this does not work in IE "yet". There is a polyfill, but that might be excessive if you don't plan on using it for anything else. It does look like object-fit is being planned for a future release of IE so once that happens this will work in all browsers.
However, if you notice the .img-responsive class in bootstrap the max-width is assuming you are putting these images in columns or something that has an explicit with set. This would mean that 100% specifically means 100% width of the parent element.
.img-responsive
max-width: 100%;
height: auto;
}
The reason we can't use that with the navbar is because the parent (.navbar-brand) has a fixed height of 50px, but the width is not set.
If we take that logic and reverse it to be responsive based on the height we can have a responsive image that scales to the .navbar-brand height and by adding and auto set width it will adjust to proportion.
max-height: 100%;
width: auto;
Usually we would have to add display:block; to the scenario, but since navbar-brand already has float:left; applied to it, it automatically acts as a block element.
You may run into the rare situation where your logo is too small. The img-responsive approach does not take this into account, but we will. By also adding the "height" attribute to the .navbar-brand > img you can be assured that it will scale up as well as down.
max-height: 100%;
height: 100%;
width: auto;
So to complete this I put them both together and it seems to work perfectly in all browsers.
<style type="text/css">
.navbar-brand>img {
max-height: 100%;
height: 100%;
width: auto;
margin: 0 auto;
/* probably not needed anymore, but doesn't hurt */
-o-object-fit: contain;
object-fit: contain;
}
</style>
<nav class="navbar navbar-default">
<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="http://disputebills.com"><img src="http://disputebills.com/site/uploads/2015/10/dispute.png" alt="Dispute Bills"></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>
</ul>
</div>
</div>
</nav>
DEMO http://codepen.io/bootstrapped/pen/KwYGwq
Although your question is interesting i don't expect there will be one answer for it. Maybe your question is too broad.
Your solution should depend on: other content in the navbar (number of items), sizes of your logo, should your logo act responsive, etc.
Adding the logo in the a (with navbar-brand) seems a good starting point. I should use the navbar-brand class because this will add a padding (top / bottom) of 15 pixels.
I test this setting on http://getbootstrap.com/examples/navbar/ with a logo of 300x150 pixels.
Full screen > 1200:
between 768 and 992 pixels (menu not collapsed):
<768 (menu collapsed)
Beside the aesthetic aspects i did not find any technical problem. On small screens a big logo will overlap or break out the viewport maybe.
Screens between 768 and 992 pixels also have other problems when the content doesn't fit in a line, see for example: https://github.com/bassjobsen/jamedo-bootstrap-start-theme/issues/18
The default navbar has The default navbar example adds a bottom-margin of 30px so the content of your navbar should never overlap the content of your page. (fixed navbars will have problems when the height of the navbar varies).
You will need some css and media queries to adapt the navbar to your need on different screen sizes. Please try to narrow your question. b.e. describe the problem you found on android.
update see http://bootply.com/77512 for an example.
On smaller screens such as a phone, the collapsed menu appears above the logo
interchange the button and the logo in your code, logo first (set float:left on the logo)
There is no way to align the menu items to anything except top
set the margin-top for .navbar-collapse ul. Use logo height minus navbar height, to align to the bottom or (logo height - navbar height) / 2 to center
Instruction how to create a bootstrap navbar with a logo which is larger than the default height (50px):
Example with a logo 100px x 100px, standard CSS:
Compute the height and (padding top + padding bottom) of the logo. Here 120px (100px height + padding top (10px) + padding bottom (10px))
Goto bootstrap / customize. Set instead of navbar height 50px > 120px (50 + 70) and navbar-collapse-max-height from 340px to 410px (340 + 70). Download css.
In this example I use this navbar. In navbar-brand:
<div class="navbar-header">
...
</button>
<a class="navbar-brand myLogo" href="#">
<img src="yourLogo.jpg" />
</a>
</div>...
add a class, for example myLogo, and an img (your logo)
<a class="navbar-brand myLogo" href="#"><img src="yourLogo.jpg" /></a>.
Add CSS
.myLogo {
padding: 10px;
}
Adequate to other sizes.
Example
Well I finally got this same problem working, here is my solution and I tested it on my site in all three major browsers: Chrome, Firefox, and Internet Explorer.
First of all if you are not using a text based logo then remove "navbar-brand" completely as I found this particular class to be the main cause of my collapsed nav menu doubling up.
Shout out to user3137032 for leading me in the right direction.
You have to make a custom responsive image container, I called mine "logo"
Here is the bootstrap HTML mark up:
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<img src="~/resources/images/Logo_Concept.png" />
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<a href="#Url.Action(" About ", "Home ")">
<i class="glyphicon glyphicon-info-sign"></i> About
</a>
</li>
<li>
<a href="#Url.Action(" Contact ", "Home ")">
<i class="glyphicon glyphicon-phone"></i> Contact
</a>
</li>
<li>
<a href="#Url.Action(" Index ", "Products ")">
<i class="glyphicon glyphicon-tag"></i> Products
</a>
</li>
</ul>
</div>
</div>
</div>
And the CSS code:
.logo img {
width: 100% \9; /*Force IE10 and below to size SVG images correctly*/
max-width: 100%;
}
#media (max-width:480px) {
.logo img {
width: 70% \9; /*Force IE10 and below to size SVG images correctly*/
max-width: 70% !important;
}
}
#media (max-width:400px) {
.logo img {
width: 75% \9; /*Force IE10 and below to size SVG images correctly*/
max-width: 75%;
}
}
#media (max-width:385px) {
.logo img {
width: 70% \9; /*Force IE10 and below to size SVG images correctly*/
max-width: 70%;
}
}
#media (max-width:345px) {
.logo img {
width: 65% \9; /*Force IE10 and below to size SVG images correctly*/
max-width: 65%;
}
}
#media (max-width:335px) {
.logo img {
width: 60% \9; /*Force IE10 and below to size SVG images correctly*/
max-width: 60%;
}
}
#media (max-width:325px) {
.logo img {
width: 55% \9; /*Force IE10 and below to size SVG images correctly*/
max-width: 55%;
}
}
#media (max-width:315px) {
.logo img {
width: 50% \9; /*Force IE10 and below to size SVG images correctly*/
max-width: 50%;
}
}
The value in #media (max-width: x) may vary depending on your logo images width, mine is 368px. The percentages may need to be changed as well depending on your logo's size. The first #media query should be your threshold and mine was image width (368px) + collapsed button size (44px) + about 60px and it came out to 480px which is where I start the responsive image scaling.
Please be sure to remove my razor syntax from the HTML portions. Let me know if it fixes your problem, it fixed mine.
Edit: Sorry, I missed your navbar height issue. There are a couple ways to go about it, personally I compile the Bootstrap LESS with the appropriate navbar height, for my purposes I use 70px, and my image height is 68 px. The second way to do it is in the bootstrap.css file itself, search for ".navbar" and change min-height: to the height of your logo.
My solution is add css "display: inline-block" to img tag.
<img style="display: inline-block; height: 30px; margin-top: -5px">
DEMO: jsfiddle
I use the img-responsive class and then set a max-width on the a element. Like this:
<nav class="navbar">
<div class="navbar-header">
<a class="navbar-brand" href="#">
<img class="img-responsive" src="mylogo.png">
</a>
</div>
</nav>
and the CSS:
.navbar-brand {
max-width: 50%;
}
You must use code as this:
<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>
<a class="logo" rel="home" href="#" title="Buy Sell Rent Everyting">
<img style=""
src="/img/transparent-white-logo.png">
</a>
</div>
Class of A tag must be "logo" not navbar-brand.
It depends on how tall you want your logo to be.
The default <a> height in the navbar is 20px, so if you specify height: 20px on your logo, it will allign nicely.
However that's kind of small for a logo, so what I opted for was this:
<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>
<a class="navbar-brand" rel="home" href="#" title="Brand">
<img style="height: 30px; margin-top: -5px;"
src="/img/brand.png">
</a>
</div>
This makes the image 30px tall and vertically aligns the image by adding a negative margin to the top (5px is half of the difference between the padding on a and the size of the image).
Alternately you could change the padding on the <a> element, eg:
<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>
<a class="navbar-brand" rel="home" href="#" title="Brand" style="padding-top: 10px; padding-bottom: 10px">
<img style="height: 30px;"
src="/img/transparent-white-logo.png">
</a>
</div>
Quick Fix : Create a class for your logo and set the height to 28px. This works well with the navbar on all devices. Notice I said works "WELL" .
.logo {
display:block;
height:28px;
}
My approach is to include FOUR different images of different sizes for phones, tablet, desktop, large desktop but only show ONE using bootstrap's responsive utility classes, as follow:
<!--<a class="navbar-brand" href="<?php echo home_url(); ?>/"><?php bloginfo('name'); ?></a>-->
<a class="navbar-brand visible-xs" href="<?php echo home_url(); ?>/"><img src="/assets/logo-phone.png" alt="<?php bloginfo('name'); ?> Logo" /></a>
<a class="navbar-brand visible-sm" href="<?php echo home_url(); ?>/"><img src="/assets/logo-tablet.png" alt="<?php bloginfo('name'); ?> Logo" /></a>
<a class="navbar-brand visible-md" href="<?php echo home_url(); ?>/"><img src="/assets/logo-desktop.png" alt="<?php bloginfo('name'); ?> Logo" /></a>
<a class="navbar-brand visible-lg" href="<?php echo home_url(); ?>/"><img src="/assets/logo-large.png" alt="<?php bloginfo('name'); ?> Logo" /></a>
Note: You can replace the commented line with the code provided. Replace the php code if you're not using wordpress.
Edit Note2: Yes, this adds requests to your server when loading the page which might slow down a bit but if you use a background css sprite technique, chances are the logo doesn't get printed when printing a page and the code above should get better SEO.
You shouldn't need to add additional CSS, since Bootstrap3 does provide it. Unless you do want to add it.
This is my code on putting the logo to the left and links to the right.
This navigation is responsive. Make changes to this as you see fit.
HTML:
<nav class="navbar navbar-expand-lg navbar-light fixed-top" style="background-color:white;">
<div class="container">
<a class="navbar-brand" href="#"><img style=" width: 150px;" src="image.jpg" alt="Image text"></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto">
<li class="nav-item"><a class="nav-link" href="#">Home</a></li>
<li class="nav-item"><a class="nav-link" href="#">Projects</a></li>
<li class="nav-item"><a class="nav-link" href="#">Blog</a></li>
<li class="nav-item"><a class="nav-link" href="#">Contact</a></li>
</ul>
</div>
</div>
</nav>
I also implement it via css background property. It works healty in any width value.
.navbar-brand{
float:left;
height:50px;
padding:15px 15px;
font-size:18px;
line-height:20px;
background-image: url("../images/logo.png");
background-repeat: no-repeat;
background-position: left center
}
Another approach is to implement Bootstrap's built-in .text-hide class alongside of .navbar-brand to replace the brand text/content with a background image.
CSS:
.navbar-brand{
background: url(http://example.com/your-logo-here.png) center / contain no-repeat;
width: 200px;
}
HTML:
<a class="navbar-brand text-hide" href="#">Navbar Brand</a>
This is a very consistent method and keeps your image centered. To adjust the size of the image all you need to do is adjust .navbar-brand width since the height is already set.
Here's a live demo
I had the same problem. I solved it like this:
<a href="#" class="btn btn-link navbar-btn">
<img class="img-responsive" src="#">
</a>
There is no navbar-brand class. The result looks like logo picture that fits navbar and works like a link. Also I recommend to use navbar-right class for the menu items so they won't go below the logo.
<div class="collapse navbar-collapse navbar-right">
<ul class="nav navbar-nav" role="navigation">
<li>Item1</li>
<li>Item2</li>
</ul>
</div>
Add the following to the .navbar-brand class
.navbar-brand
{
padding: 0px; // this allows the image to occupy all the padding space of the navbar--brand
}
.navbar-brand > img
{
height: 100%; // set height to occupy full height space on the navbar-brand
width: auto; // width should be auto to allow img to scale accordingly
max-height: 100%; // optional
margin: 0 auto; // optional
}
Maybe this is too simple, but I just copied the navbar-brand line so there are two of them, the image and then the text.
<a class="navbar-brand" href="index.php"><img class="img-responsive" src="images/my-icon.png" width="30" height="25" alt=" "></a>
<a class="navbar-brand" href="index.php">My Brand</a>
And I created an image that fits inside the navbar (roughly 1/2 the height).
If using LESS, this works:
#navbar-height: 150px;
#navbar-brand-vpadding: 10px;
.navbar-brand img {
height: #navbar-height - #navbar-brand-vpadding * 2;
position: absolute;
top: #navbar-brand-vpadding;
}
This code works perfect if you need to see the brand centered and with auto width in toolbar.
It contains the Wordpress function to get the image file from right path:
<a class="navbar-brand page-scroll" rel="home"
href="#page-top" title="Title">
<img style="height: 100%; width: auto;"
src="<?php echo get_template_directory_uri();?>/img/logo.png">
my working code - bootstrap 3.0.3.
when navbar-toggle, hidden-xs original logo image.
<a class="navbar-brand hidden-xs" href="<?=$g4['path']?>/">
<img src="<?=$g4[path]?>/images/logo_opencode.gif" align=absmiddle alt="brand logo">
</a>
<a class="navbar-brand navbar-toggle" href="<?=$g4['path']?>/" style="border:0;margin-bottom:0;">
<img src="<?=$g4[path]?>/images/logo_opencode.gif" alt="brand logo" style="width:120px;">
</a>
You might try using #media query such as below.
Add a logo class first, then use #media to specify your logo height and width per device size. In the example below, I am targeting devices which have a max width of 320px (iPhone) You can play around with this until you find the best fit. Easy way to test: Use chrome or Firefox with inspect element. Shrink your browser as far as possible. Observe the logo size change based on the #media max width you specify. Test on iPhone, android devices, iPad etc to get the desired results.
.logo {
height: 42px;
width: 140px;
}
#media (max-width:320px) {
.logo {
height: 33px;
width: 110px;
}
}
Please try following code:
<style>
.navbar a.navbar-brand {padding: 9px 15px 8px; }
</style>
<a class="navbar-brand" href="#">
<img src="http://placehold.it/140x34/000000/ffffff/&text=LOGO" alt="">
</a>
Failing to make any of the other answers work in my case (I probably didn't pass the intelligence test) and after some experimentation, this is what I am using (which I believe is very close to the Bootstrap default):
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" 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 class="navbar-logo">
<a class="navbar-brand" rel="home" href="#Url.Action("Index", "Home")" title="Home">
<img src="~/Images/logo.png" class="img-responsive">
</a>
</div>
<div class="collapse navbar-collapse" id="navbar-collapse">
<ul class="nav navbar-nav">
<li>#Html.ActionLink("Home", "Index", "Home")</li>
<li>#Html.ActionLink("Coaching", "Coaching", "Home")</li>
<li>#Html.ActionLink("Resources", "Resources", "Home")</li>
<li>#Html.ActionLink("Contact", "Contact", "Home")</li>
<li>#Html.ActionLink("Blog", "Blog", "Home")</li>
<li>#Html.ActionLink("About", "About", "Home")</li>
</ul>
</div>
</div>
</div>
And in the CSS file I have added the following:
.navbar-brand {
padding-top: 5px;
}
.navbar-collapse {
float: left;
}
.navbar-logo {
float: left;
}
Note that #Html.ActionLink() is Razor syntax for an <a> tag. Where it says #Html.ActionLink(...) just replace it with an appropriate <a> tag. Equally where it says #Url.Action(...) replace it with an appropriate URL (no <a> tag in that case).
This isn't semantic but I just use the existing a element, set a background image, then create multiple variations for #2x resolution, smaller screen sizes, etc.
Then, you can use the .text-hide class to get some text on the page the ol' fashion way. Simple and effective though not proper use of an image.
Here's a link to the helper class for text-replacement:
http://getbootstrap.com/css/#helper-classes
The easiest and best answer for this question is to set a max width and height depending on your logo, the image will be a max of 50px high but no longer than 200px.
<a href="index.html">
<img src="imgs/brand-w.png" style="max-height:50px;max-width:200px;">
</a>
This will vary depending on your logo size and the nav bar items you have.
<header class="navbar navbar-inverse header-outer" role="banner">
<div class="container form-inline">
<img src="#Url.Content(" ~/Content/img/Logo-Sample.png ")" alt="Image" id="logo" class="img-responsive pull-left" />
<div class="pull-right padding-top">
<form class="hidden-xs" role="form">
<div class="form-group" style="padding-left:10px">
<input type="email" class="form-control" id="exampleInputEmail2" placeholder="Username">
</div>
<div class="form-group">
<input type="password" class="form-control" id="exampleInputPassword2" placeholder="Password">
</div>
<div class="form-group navbar-remember">
<label class="white-font">
<input type="checkbox" class="white-font"> Remember me
</label>
</div>
<button type="button" class="btn btn-primary form-group" title="Sign In">Sign In</button>
</form>
</div>
</div>
</header>
Please understand the code at your own effort :D This is my draft code and its already working :) Here's the screenshot.
In stead of replacing text branding, I divided into two rows like in the code below and gave img-responsive class to the image......
<div class="collapse navbar-collapse navbar-ex1-collapse" style="background: #efefef; height:auto;">
<div class="container" style="margin-bottom:-1px;">
<div class="row">
<div class="col-md-3">
<div id="menubar-logo">
<img src="img/tl_logo.png" class="img-responsive" alt="Triple Luck IT Service Logo">
</div>
</div>
<div class=" col-md-offset-3 col-md-6">
<ul class="nav navbar-nav">
<li>Home</li>
<li>About Us</li>
<li>Contact Us</li>
</ul>
</div>
</div>
<!-- end of "row" -->
</div>
<!-- end of "container" -->
</div>
<!-- end of "collapse" -->
and in addition,I added the following css codes.......
#menubar-logo img {
margin-top: 10px;
margin-bottom: 20px;
margin-right: 10px;
}
If my code solves your problem, it's my pleasure.....
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header" >
<button type="button" class="navbar-toggle" 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>
<a class="navbar-brand" href="Default.aspx"> <span> <img alt="Logo" src="Images/shopify-bag.png"height="35" width="40"/></span> Shopping GO</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right"></ul>
//Don't forgot to add bootstrap in head of your code.

Resources