偏斜引导导航列表项和保持链接直

时间:2015-09-18 20:35:45

标签: html css twitter-bootstrap skew

我正在尝试使用CSS transform来扭曲bootstrap nav li,我可以实现这一点,但是当我尝试扭转内部链接的偏斜时,li偏斜也会反转。我不知道为什么。我尝试做了接受的答案中提到的内容:How to skew element but keep text normal (unskewed)

然而,虽然它似乎与该代码一起使用,但它不适用于bootstrap nav ul li。

请参阅问题(忽略此问题):http://jsfiddle.net/dfqzkqL5/

更正:http://jsfiddle.net/dfqzkqL5/3/

.skew li {
  display:inline-block;
  transition: background 0.2s;
  transform: skew(-20deg);
  -moz-transform: skew(-20deg);
  -ms-transform: skew(-20deg);
  -webkit-transform: skew(-20deg);
  -o-transform: skew(-20deg);
}

.noskew {
     display:inline-block;
  transition: background 0.2s;
  transform: skew(20deg);
  -moz-transform: skew(20deg);
  -ms-transform: skew(20deg);
  -webkit-transform: skew(20deg);
  -o-transform: skew(20deg);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>

<nav class="navbar navbar-default">
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <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>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav skew">
        <li class="active"><a href="#" class="noskew">Link <span class="sr-only">(current)</span></a></li>
        <li><a href="#" class="noskew">Link</a></li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded=" class="skew"false">Dropdown <span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="#" class="noskew">Action</a></li>
            <li><a href="#" class="noskew">Another action</a></li>
            <li><a href="#" class="noskew">Something else here</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="#" class="noskew">Separated link</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="#" class="noskew">One more separated link</a></li>
          </ul>
        </li>
      </ul>
      <form class="navbar-form navbar-left" role="search">
        <div class="form-group">
          <input type="text" class="form-control" placeholder="Search">
        </div>
        <button type="submit" class="btn btn-default">Submit</button>
      </form>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="#">Link</a></li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></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 role="separator" class="divider"></li>
            <li><a href="#">Separated link</a></li>
          </ul>
        </li>
      </ul>
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>

我只是想通过bootstrap导航栏实现这一目标。有什么想法吗?

提前致谢。

1 个答案:

答案 0 :(得分:1)

您的原始偏差被应用了两次,因为您的CSS规则skew li与外部列表中的li以及内部列表中的skew > li匹配。要解决此问题,请改用CSS library (raster) library(rasterVis) f <- system.file("external/test.grd", package="raster") r <- raster(f) levelplot(r) ,以便仅将偏斜应用于外部列表。当歪斜仅应用一次时,反向歪斜将正常工作。

截图:

Screenshot

修正了JSFiddle:http://jsfiddle.net/dfqzkqL5/2/