CSS背景图片仅作为nav bg

时间:2017-11-17 09:00:16

标签: html background navbar listitem

我想仅为导航栏中的列表项设置背景。它应该是连续的所有li。导航的div容器是整个站点的宽度。有没有可能这样做?我无法使用px中的margin,因为该站点必须具有响应性。

1 个答案:

答案 0 :(得分:0)

例如:如果导航看起来像这样

   <div class="container">
    <nav class="navbar navbar-default navbar-custom" role="navigation">
        <div class="container-fluid">
          <!-- Brand and toggle get grouped for better mobile display -->
          <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
              <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="#">Brand</a>
          </div>

          <!-- Collect the nav links, forms, and other content for toggling -->
          <div class="collapse navbar-collapse navbar-ex1-collapse">
            <ul class="nav navbar-nav">
              <li class="active"><a href="#">Link 1</a></li>
              <li><a href="#">Link 2</a></li>
              <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a>
                <ul class="dropdown-menu">
                  <li><a href="#">Action</a></li>
                  <li><a href="#">Another action</a></li>
                  <li><a href="#">Something else here</a></li>
                  <li><a href="#">Separated link</a></li>
                  <li><a href="#">One more separated link</a></li>
                </ul>
              </li>
            </ul>

            </div><!-- /.navbar-collapse -->
        </div>
    </nav>
</div>

使用代码:

.navbar{
  background: url('http://wallpapers.wallhaven.cc/wallpapers/full/wallhaven-169280.jpg');

}

检查一下 https://codepen.io/anon/pen/jaaaWm