Bootstrap Underline Nav Link

时间:2016-11-07 17:15:18

标签: html css twitter-bootstrap

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<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="#bs-example-navbar-collapse-1" aria-expanded="false">
            <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>
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
          <!--<ul class="nav navbar-nav">
            <li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
            <li><a href="#">Link</a></li>
          </ul>-->
          <ul class="nav navbar-nav navbar-right">
            <li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
            <li><a href="#">Link</a></li>
            <li><a href="#">Link</a></li>
          </ul>
        </div>
      </div>
    </nav>

我在使用这段代码时遇到了问题:

.navbar-default .navbar-nav > .active > a:after {
   content: "";
   position: absolute;
   width: 100%;
   height: 3px;
   bottom: 0;
   left: 0;
   background-color: #1B94E1;

    -webkit-transform: scaleX(0);
            transform: scaleX(0);
   -webkit-transition: all 0.3s ease-in-out 0s;
           transition: all 0.3s ease-in-out 0s;
}

基本上,我想使用CSS ::after伪类来创建一个下划线。然而,似乎没有任何事情发生。请注意,我正在使用Bootstrap并将这些样式应用于导航栏。谢谢!

这是一个codepen:http://codepen.io/Hudson_Taylor11/pen/ZBGGXQ

2 个答案:

答案 0 :(得分:0)

评论你的过渡修复了它。

.navbar-default .navbar-nav > .active > a:after {
   content: "";
   position: absolute;
   width: 100%;
   height: 3px;
   bottom: 0;
   left: 0;
   background-color: #1B94E1;

  /*  -webkit-transform: scaleX(0);
            transform: scaleX(0);
    -webkit-transition: all 0.3s ease-in-out 0s;
           transition: all 0.3s ease-in-out 0s;
  */
}

http://codepen.io/0rfila/pen/rWVVqj

以下是有关动画伪像的更多信息:https://cssanimation.rocks/pseudo-elements/

答案 1 :(得分:0)

这是工作码本

.navbar-default .navbar-nav a { border-bottom: 2px solid red; padding: 0px; margin: 15px; }

http://codepen.io/SESN/pen/QGbbmL