Bootstrap 4 - 响应式水平导航

时间:2017-01-21 11:34:08

标签: html css twitter-bootstrap

我遇到了Bootstrap 4导航系统的问题,如果导航容器的宽度太小,导航链接就会悬空。移动设备经常出现这种情况。

以下是一个示例:http://codepen.io/anon/pen/ZLKGrx

<div class="container">
  <div class="row">
    <div class="col-6 offset-3 columnbg">
      <ul class="nav nav-pills">
        <li class="nav-item">
          <a class="nav-link active" href="#">LongTabName</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">LongTabName</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">LongTabName</a>
        </li>
        <li class="nav-item">
          <a class="nav-link disabled" href="#">LongTabName</a>
        </li>
        <li class="nav-item">
          <a class="nav-link disabled" href="#">LongTabName</a>
        </li>
      </ul>
    </div>
  </div>
</div>

我想要实现适合小型显示器的东西。我该怎么做?

3 个答案:

答案 0 :(得分:1)

Bootstrap专为移动优先而构建。您遇到此问题的唯一原因是您没有完全实施navbar

&#13;
&#13;
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>

<nav class="navbar navbar-toggleable-md navbar-light bg-faded">
  <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <a class="navbar-brand" href="#">Navbar</a>

  <div class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Link</a>
      </li>
      <li class="nav-item">
        <a class="nav-link disabled" href="#">Disabled</a>
      </li>
    </ul>
    <form class="form-inline my-2 my-lg-0">
      <input class="form-control mr-sm-2" type="text" placeholder="Search">
      <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
    </form>
  </div>
</nav>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

css中的一个技巧可以帮助您根据屏幕宽度指定要调整大小的元素。高度:

String originalDate = "2016-10-30 23:35";
LocalDateTime localTime = LocalDateTime.parse(originalDate, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));
ZonedDateTime utcTime = localTime.atZone(ZoneOffset.UTC);
ZonedDateTime bstTime = utcTime.withZoneSameInstant(ZoneId.of("Europe/London"));
// the summer time offset is how many milliseconds?
long dstOffset = ChronoUnit.MILLIS.between(utcTime.toLocalDateTime(), bstTime.toLocalDateTime());
System.out.println(dstOffset); // prints 0

// try the same at start of day (midnight)
utcTime = utcTime.toLocalDate().atStartOfDay(ZoneOffset.UTC);
bstTime = utcTime.withZoneSameInstant(ZoneId.of("Europe/London"));
dstOffset = ChronoUnit.MILLIS.between(utcTime.toLocalDateTime(), bstTime.toLocalDateTime());
System.out.println(dstOffset); // prints 3600000

// and next midnight
utcTime = utcTime.plusDays(1);
bstTime = utcTime.withZoneSameInstant(ZoneId.of("Europe/London"));
dstOffset = ChronoUnit.MILLIS.between(utcTime.toLocalDateTime(), bstTime.toLocalDateTime());
System.out.println(dstOffset); // prints 0

如您所见,当屏幕宽度低于600px时(移动设备应该更小),@media (max-width: 600px) { .row { //change width here } } css将覆盖;)

答案 2 :(得分:0)

col-6在最小屏幕上仅为半宽,因此无法准确模拟移动屏幕宽度。当导航内容对于移动宽度来说太长时,您可以使用其他实用程序类之一在导航中显示更少的内容(缩写标签或仅图标)。

<ul class="nav nav-pills">
        <li class="nav-item">
          <a class="nav-link active" href="#"><span class="hidden-xs-down">LongTabName</span><span class="hidden-sm-up">TN</span></a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#"><span class="hidden-xs-down">LongTabName</span><span class="hidden-sm-up">TN</span></a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#"><span class="hidden-xs-down">LongTabName</span><span class="hidden-sm-up">TN</span></a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#"><span class="hidden-xs-down">LongTabName</span><span class="hidden-sm-up">TN</span></a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#"><span class="hidden-xs-down">LongTabName</span><span class="hidden-sm-up">TN</span></a>
        </li>
      </ul>

http://www.codeply.com/go/WXqhlCDp9o