没有徽标调整大小的粘性顶部导航栏

时间:2017-12-04 21:05:12

标签: html css twitter-bootstrap

我有以下代码:



<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<nav class="navbar navbar-default navbar-fixed-top">
  <div class="container">
    <div class="row">
    
      <nav class="col-sm-6">
        <span class="pull-left">
          <a href="#" class="navbar-left">
            <img src="img/gyn.png" alt="" class="logo">
          </a>
        </span>
      </nav>

      <nav class="col-sm-6">
        <span class="pull-right">
          <ul class="nav navbar-nav thmbl">
            <li><a  class="tupac" href="#team"><strong>TEAM</strong></a></li>
            <li><a class="tupac" href="#services"><strong>SERVICES</strong></a></li>
            <li><a class="tupac" href="#gal"><strong>GALLERY</strong></a></li>    
            <li><a class="tupac" href="#location"><strong>LOCATION</strong></a></li>
          </ul>
        </span>
      </nav>
      
    </div>
  </div>
</nav>
&#13;
&#13;
&#13;

对于我的生活,我无法理解为什么徽标以完整尺寸显示而不包含在Navbar中。我基本上想要左侧的徽标和右侧的菜单项。此外,我希望它们始终位于samle线上,即当我调整窗口大小时(或者像iPhone一样在较小的屏幕上)时,它会缩小。也许我有隧道视觉,但任何人都可以指出这个问题吗?

1 个答案:

答案 0 :(得分:0)

在不查看css的情况下无法确定,但只有在正确配置徽标类的情况下才会调整图像大小。您可能需要查看此示例https://codepen.io/bootstrapped/pen/KwYGwq,了解如何正确配置css。

对于涉及包装的问题,默认行为是特别包装,因为当您将屏幕划分为2列时较小。一个选项是使用CSS(参见How to make bootstrap 3 navbar not wrap)。或者,使用列大小进行播放,以便小徽标不会占用半屏空间,并且菜单项可以正确缩放。对于非常小的屏幕,最好的选择是折叠并显示垂直菜单。

来自bootply的这段代码可以满足您的需求:

    <div class="container example2">
  <nav class="navbar navbar-default">
    <div class="container-fluid">
      <div class="navbar-header">
        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar2">
          <span class="sr-only">Toggle navigation</span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </button>
        <a class="navbar-brand" href="http://disputebills.com"><img src="https://res.cloudinary.com/candidbusiness/image/upload/v1455406304/dispute-bills-chicago.png" alt="Dispute Bills">
        </a>
      </div>
      <div id="navbar2" class="navbar-collapse collapse">
        <ul class="nav navbar-nav navbar-right">
          <li class="active"><a href="#">Home</a></li>
          <li><a href="#">About</a></li>
          <li><a href="#">Contact</a></li>
          <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Dropdown <span class="caret"></span></a>
            <ul class="dropdown-menu" role="menu">
              <li><a href="#">Action</a></li>
              <li><a href="#">Another action</a></li>
              <li><a href="#">Something else here</a></li>
              <li class="divider"></li>
              <li class="dropdown-header">Nav header</li>
              <li><a href="#">Separated link</a></li>
              <li><a href="#">One more separated link</a></li>
            </ul>
          </li>
        </ul>
      </div>
      <!--/.nav-collapse -->
    </div>
    <!--/.container-fluid -->
  </nav>
</div>

这是CSS

.navbar-brand {
  padding: 0px;
}
.navbar-brand>img {
  height: 100%;
  padding: 15px;
  width: auto;
}


/* EXAMPLE 2 (larger logo) - simply adjust top bottom padding to make logo larger */

.example2 .navbar-brand>img {
  padding: 7px 15px;
}



/* CSS Transform Align Navbar Brand Text ... This could also be achieved with table / table-cells */
.navbar-alignit .navbar-header {
      -webkit-transform-style: preserve-3d;
  -moz-transform-style: preserve-3d;
  transform-style: preserve-3d;
  height: 50px;
}
.navbar-alignit .navbar-brand {
    top: 50%;
    display: block;
    position: relative;
    height: auto;
    transform: translate(0,-50%);
    margin-right: 15px;
  margin-left: 15px;
}





.navbar-nav>li>.dropdown-menu {
    z-index: 9999;
}

body {
  font-family: "Lato";
}