Bootstrap - How to add a logo to navbar class?

后端 未结 7 1465
傲寒
傲寒 2021-02-08 19:08

I would like to add a logo to the top navbar within the navbar-brand. I would like it to scale with the viewport size so I\'m using img-responsive2 class.

It appear that

相关标签:
7条回答
  • 2021-02-08 19:30

    Use a image style width and height 100% . This will do the trick, because the image can be resized based on the container.

    Example:

    <a class="navbar-brand" href="#" style="padding: 4px;margin:auto"> <img src="images/logo.png" style="height:100%;width: auto;" title="mycompanylogo"></a>
    
    0 讨论(0)
  • 2021-02-08 19:35

    Enter the image and give height:100%;width:auto then just change the height of navbar itself to resize image. There is a really good example in codepen. https://codepen.io/bootstrapped/pen/KwYGwq

    0 讨论(0)
  • 2021-02-08 19:37

    I found a solution on another thread that works - use the pull-left class:

     <a href="#" class="pull-left"><img src="/path/to/image.png"></a> 
    

    Thanks to Michael in this thread:

    Bootstrap - How to add a logo to navbar class?

    0 讨论(0)
  • 2021-02-08 19:38
    <a class="navbar-brand" href="#" style="padding:0px;">
      <img src="mylogo.png" style="height:100%;">
    </a>
    

    For including a text:

    <a class="navbar-brand" href="#" style="padding:0px;">
      <img src="mylogo.png" style="height:100%;display:inline-block;"><span>text</span>
    </a>
    
    0 讨论(0)
  • 2021-02-08 19:41

    You can just display both the text and image as inline-blocks so that they dont stack. using floats like pull-left/pull-right can cause undesired issues so they should be used sparingly

    <a class="navbar-brand" href="#">
      <img src="mylogo.png" style="display: inline-block;">
      <span style="display: inline-block;">My Company</span>
    </a>
    
    0 讨论(0)
  • 2021-02-08 19:42

    I would suggest you to use either an image or text. So, Remove the text and add it in your image(using Photoshop, maybe). Then, Use a width and height 100% for the image. it will do the trick. because the image can be resized based on the container. But, you have to manually resize the text. If you can provide the fiddle, I can help you achieve this.

    0 讨论(0)
提交回复
热议问题