简体   繁体   English

垂直引导导航栏按钮未对齐

[英]Vertical Bootstrap Navbar Button Misaligned

I'm working on a responsive navigation bar with Bootstrap for my website. 我正在为我的网站使用Bootstrap开发响应式导航栏。 I have it mostly figured out, except for one thing. 除了一件事,我基本上已经弄清楚了。 On devices with screen width < ~775px , such that the buttons are stacked vertically instead of horizontally, the first one extends a bit to the left, misaligning it with the rest of the buttons. 在屏幕width < ~775px设备上,使按钮垂直堆叠而不是水平堆叠,第一个按钮向左延伸一点,使它与其余按钮未对齐。 What is causing this, and how do I fix it? 是什么原因造成的,该如何解决?

JSFiddle: https://jsfiddle.net/w10cspvv/ JSFiddle: https ://jsfiddle.net/w10cspvv/

HTML: HTML:

<div id="navbar">
  <nav class="navbar navbar-default">
    <div class="container-fluid">
      <ul class="nav nav-pills nav-justified">
        <li role="presentation" class="active navbutton">
          <a href="/"><img class='squidanim' src='https://www.glowingsquid.com/images/squid.gif' /><span>Home</span></a>
        </li>
        <li role='presentation' class='active navbutton'>
          <a href='/about.php'><img class='squidanim' src='https://www.glowingsquid.com/images/squid.gif' /><span>About</span></a>
        </li>
        <li role='presentation' class='active navbutton'>
          <a href='/contact.php'><img class='squidanim' src='https://www.glowingsquid.com/images/squid.gif' /><span>Contact</span></a>
        </li>
      </ul>
    </div>
  </nav>
</div>

CSS: CSS:

body {
  background-color: black;
  font-size: 16pt;
  margin-top: 2em;
}

#navbar {
  border: .25em solid #00aeef;
  background-color: #00aeef;
  border-radius: 25px;
}

.navbar {
  margin-bottom: 0em;
}

.navbar-default {
  border-radius: 25px;
  border-color: #00aeef;
  background: #00aeef;
}

.main {
  font-family: Ubuntu, Tahoma, Geneva, sans-serif;
  margin-left: 6em;
  margin-right: 6em;
  text-align: center;
}

.nav-pills > li.active > a,
.nav-pills > li.active > a:focus,
.nav-pills > li.active > a:hover {
  background-color: #7F00FF;
}

.squidanim {
  display: none;
}

.navbutton:hover a > .squidanim {
  display: block;
  height: 50px;
  position: absolute;
  z-index: 100;
}

.navbutton {
  padding-left: 2em;
  padding-right: 2em;
}

.nav > li > a {
  padding-top: 0;
  padding-bottom: 0;
}

.nav > li > a > span {
  padding-top: 10px;
  padding-bottom: 10px;
}

@media (max-width: 978px) {
  #navbar {
    margin-left: 2em;
    margin-right: 2em;
  }
  .main {
    margin-left: 1em;
    margin-right: 1em;
  }
  .navbutton {
    padding-left: 0;
    padding-right: 0;
  }
}

I have fixed this in this JSFiddle: https://jsfiddle.net/xpn779Lr/1/ 我已在此JSFiddle中修复此问题: https ://jsfiddle.net/xpn779Lr/1/

Which overrides the default bootstrap rule 它将覆盖默认的引导程序规则

.nav-pills>li+li {
  margin-left: 2px;
}

to

.nav-pills>li+li {
  margin-left: 0;
}

FYI, this css rule has high specificity. 仅供参考,此CSS规则具有很高的特异性。

The plus sign mean that the style applies only to li's directly following another li. 加号表示该样式仅适用于直接位于另一个li之后的li。 A plain "li" selector would apply the style to every li in the div with a "navpills" class. 一个简单的“ li”选择器将使用“ navpills”类将样式应用于div中的每个li。

See adjacent selectors on W3.org. 请参阅W3.org上的相邻选择器

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

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