繁体   English   中英

文本与bootstrap的navbar-text pull-right无法正确对齐

[英]Text not aligning properly with bootstrap's navbar-text pull-right

我在html文件中有以下代码:

 <div class="navbar navbar-fixed-top">
          <div class="navbar-inner">
              <div class="container-fluid">
                  <a href="index.html" class="brand">Hello Bootstrap</a>
                  <p class="navbar-text pull-right">This is first notice.</p><br/>
                  <p class="navbar-text pull-right">This is second notice. </p>
              </div>
          </div>
  </div>

我得到这样的输出:

在此输入图像描述

请注意,“这是第二次通知”与其上方的行没有正确对齐。 我试图让两个通知彼此正确对齐。

我也尝试从上面的代码中删除<br/>但是我得到了以下输出: 在此输入图像描述

有人可以指出我做错了什么吗?

JSFiddle: http//jsfiddle.net/N6vGZ/23/

这两个段落在导航栏中没有正确对齐的原因是因为bootstraps提出的默认line-height 40px不允许它们都正确堆叠。 您可以通过设置较低的line-height来解决这个问题,像20px这样的东西应该可以解决问题。

注意:我在容器中包含了两个段落,我可以轻松地浮动并使用我自己的类进行定位,以免打扰周围的其他元素。

HTML

<div class="navbar navbar-fixed-top">
    <div class="navbar-inner">
        <div class="container-fluid">
            <a href="index.html" class="brand">Hello Bootstrap</a>
            <div class="notices pull-right">
                <p class="navbar-text">This is first notice.</p>
                <p class="navbar-text">This is second notice.</p>
            </div>
        </div>
    </div>
</div>

试试这个:

CSS

.notices p {
    line-height:20px !important;
}

演示: http//jsfiddle.net/N6vGZ/29/

你没有包含css,但我认为你在“右拉”课上有“浮动:正确”。

我认为解决问题的最简单方法是将两个p包装在他们自己的div中,然后向下浮动:

<div class="navbar navbar-fixed-top">
      <div class="navbar-inner">
          <div class="container-fluid">
              <a href="index.html" class="brand">Hello Bootstrap</a>
              <div class="pull-right">
                   <p class="navbar-text">This is first notice.</p>
                   <p class="navbar-text">This is second notice. </p>
              </div>
          </div>
      </div>

如果您还没有忘记在CSS中的“右拉”类上设置宽度。

你可以使用带导航类的ul和带右拉的li

http://jsfiddle.net/N6vGZ/28/

暂无
暂无

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

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