简体   繁体   English

如何将导航栏品牌与其余链接对齐

[英]How to align navbar-brand with rest of links

If I use an image along side a link, the navbar is getting bigger. 如果我在链接旁使用图片,则导航栏会越来越大。

<ul class="nav navbar-nav navbar-right">
    <li class="dropdown">
        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
                <img src="..." /> // this is causing the problem 
             Me<span class="caret"></span>
                  </a>
        <ul class="dropdown-menu" role="menu">
            <li><a>Sample 1</a>
            </li>
            <li class="divider"></li>
            <li><a>Sample 1</a>
            </li>
        </ul>
    </li>
</ul>

The result is http://jsfiddle.net/6xzwdwfr/18/embedded/result/ . 结果是http://jsfiddle.net/6xzwdwfr/18/embedded/result/ But how do I make it so that it looks like http://jsfiddle.net/6xzwdwfr/21/embedded/result/ ? 但是如何使它看起来像http://jsfiddle.net/6xzwdwfr/21/embedded/result/

Basically, I want to make sure that adding the image doesn't cause the navbar to enlarge. 基本上,我要确保添加图像不会导致导航栏扩大。

I tried lessening some of the paddings and margins in the nav* classes, but it only made the matters worse. 我尝试减少了nav*类中的某些填充和边距,但这只会使情况变得更糟。

How can I adjust it? 我该如何调整?

Remove top and bottom paddings from .navbar-nav > li > a 从.navbar-nav> li> a删除顶部和底部填充

.navbar-nav > li > a {
  padding: 0px 12px;
  margin: 12.5px 6px;
  border: 1px solid transparent;
  border-radius: 4px;
}

如果您想要将图像放在导航栏中以使其适合并保持该比例,则可以查看以下已回答的帖子: 如何在div内适合图像(img)并保持纵横比?

Try re-sizing the <a> that contains the image by adding the following code: 尝试通过添加以下代码来调整包含图像的<a>的大小:

li.dropdown > a {
    height: 34px;
}

This way, the <a> element doesn't take up any more space than the <img> it contains. 这样, <a>元素<a>空间不会比其包含的<img> I tried it in your Fiddle and it worked. 我在您的小提琴中尝试了一下,并且效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM