Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resize bootstrap navbar brand logo keeping proportions

I was wondering if there's a way to dinamically resize the navbar brand logo image to have the exact height of the navbar itself and calculate the width keeping the image proportion.

<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="#"><img alt="Brand" src="images/logo.png"></a>
    </div>

I tried to edit the bootstrap .css adding:

.navbar .brand > img { max-height: 40px; }

or:

.navbar .brand { 
    max-height: 40px;
    max-width: 30%; 
    overflow: visible;
    padding-top: 0;
    padding-bottom: 0; 
}

with no luck, the image remains with the same giant size.

The first one should do the trick, I want these settings to be applied inside the img tag inside the a tag with navbar-brand class, but, even if the css is refreshed correctly, these settings are not applied to my image.

like image 315
lateralus Avatar asked May 27 '15 09:05

lateralus


People also ask

How do I change the navbar logo size?

Open your image in Preview - Go to Tools/AdjustSize: Then you can change your width or height to the desired size. Make sure to keep Scale Proportionally checked!

What is a good size for a navbar logo?

Navigation Bar Logo Size While the exact sizing will depend on your specific website builder, it's likely that the size options will be approximately as follows: Full banner: 468 x 60 pixels. Horizontal layout: 250 x 150 pixels; 350 x 75 pixels; or 400 x 100 pixels. Vertical layout: 160 x 160 pixels.

How do I make my image navbar responsive?

You can wrap your image in an anchor tag and give it a class of navbar-brand and give the image an id. You need to specify what size you want your image to be. use #logo{ width: 50px; height: 50px;} 50px; is just an example you would need to use a height and width that will work best for you.

How do I align navbar brand to right?

ml-auto class in Bootstrap can be used to align navbar items to the right. The . ml-auto class automatically aligns elements to the right.


1 Answers

In the CSS you provided, you may be referencing the wrong class name. You would need to override the .navbar-brand class, but you are referencing a .brand class name within .navbar. As such, the styles will not be applied to the element you are wanting it to.

Also, did you try using the class="img-responsive"on the image?

<a class="navbar-brand" href="#"><img alt="Brand" src="images/logo.png" class="img-responsive" /></a>

Otherwise, take a look at this Stackoverflow article, as it is similar: Bootstrap 3 Navbar with Logo.

Hope this helps your cause.

like image 100
cfnerd Avatar answered Sep 24 '22 03:09

cfnerd