I have a 1700×700 logo and my navbar height is 70. I would like to auto-resize and adapt it to my navbar height. I could resize it to 170×70 with photoshop but the problem is that the image loses quality when I zoom on.
I tried with img-responsive but it doesn’t work.
Thank you!
<a class="navbar-brand" href="index.php"></a>
.navbar-brand
{
position: relative;
background: url(../images/logo.png);
width: 170px;
left: 15px;
}
8
Answers
You can set following css for this
Did you the below one you need not give any external css.
<a class="navbar-brand" href="#"><img alt="Brand" src="images/logo.png" class="img-responsive" /></a>
Give your logo
max-height
and make the value to be the height of the navbar like so…you can use this css
background: url(../images/logo.png) no-repeat scroll center center / contain ;
The best option is resizing the logo in Photoshop (or similar).
Of course if it is displayed in less pixels it loses resolution, but if you load a big logo and then you resize it via css the effect is going to be the same and your page will take more time to load.
Agree with ABK as far as max-height CSS, but I think JGonDev on resizing the image is the right direction for a performance standpoint. You really should only use CSS to style and design your site. It should not be used to hack your code to force the needed desire.
As far as resizing, most new developers don’t have access to great design tools like Photoshop, but great if you can! For Mac users, Preview gets the job done for resizing images.
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! This will ensure your image does not get skewed.
After you resize, click ‘OK’ button. File Save.
** Note – Make sure you save your file as a different file, i.e. navbar-logo.png or something similar so you can easily remember what the image should be used for in your code.
Resizing your image will reduce the bloat and size of your overall website and improve the overall performance of your site.
**Simplest Answer to your question is **
If you find it useful don’t forget to UPVOTE
The navbar you will ever need
Use
flex
with thatjustify-content
justifies content automatically adjust items into positionalign-items:center
, well it’s self explanatoryAdjust it to your need my liege