带箭头的Bootstrap手风琴

时间:2016-06-23 06:52:08

标签: html css twitter-bootstrap

我对Bootstrap手风琴有一个简单的问题。

我创建了一个手风琴女巫可以在标题上点击以扩展。这很有效但我的问题是标题中没有显示箭头。

.panel-heading [data-toggle="collapse"]:after {
  font-family: 'Glyphicons Halflings';
  content: "\e072";
  /* "play" icon */
  float: right;
  color: #b0c5d8;
  font-size: 18px;
  line-height: 22px;
  /* rotate "play" icon from > (right arrow) to down arrow */
  -webkit-transform: rotate(-90deg);
  -moz-transform: rotate(-90deg);
  -ms-transform: rotate(-90deg);
  -o-transform: rotate(-90deg);
  transform: rotate(-90deg);
}

.panel-heading [data-toggle="collapse"].collapsed:after {
  /* rotate "play" icon from > (right arrow) to ^ (up arrow) */
  -webkit-transform: rotate(90deg);
  -moz-transform: rotate(90deg);
  -ms-transform: rotate(90deg);
  -o-transform: rotate(90deg);
  transform: rotate(90deg);
}
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js"></script>
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css" rel="stylesheet"/>
<!-- Accordion START -->
<div class="panel-group" id="accordion">
  <div class="panel panel-default">
    <div class="panel-heading accordion-toggle collapsed" data-toggle="collapse" data-parent="#accordion" data-target="#collapseOne">
      <h4 class="panel-title">Test1</h4>

    </div>
    <div id="collapseOne" class="panel-collapse collapse">
      <div class="panel-body">
        <p>sadfsadfsdaf sadf</p>
      </div>
    </div>
  </div>
  <div class="panel panel-default">
    <div class="panel-heading accordion-toggle collapsed" data-toggle="collapse" data-parent="#accordion" data-target="#collapseTwo">
      <h4 class="panel-title">Test2</h4>

    </div>
    <div id="collapseTwo" class="panel-collapse collapse">
      <div class="panel-body">
        <p>
          Bla bla bla
        </p>
      </div>
    </div>
  </div>
</div>
<!-- Accordion END -->

2 个答案:

答案 0 :(得分:11)

选择器之间存在问题:

.panel-heading [data-toggle="collapse"]:after
              ^------- // remove this space to make this selector work

现在,您选择的所有元素都具有data-toggle属性,这些元素是.panel-heading的后代。它应该是:

.panel-heading[data-toggle="collapse"]:after

&#13;
&#13;
.panel-heading {
  position: relative;
}
.panel-heading[data-toggle="collapse"]:after {
  font-family: 'Glyphicons Halflings';
  content: "\e072"; /* "play" icon */
  position: absolute;
  color: #b0c5d8;
  font-size: 18px;
  line-height: 22px;
  right: 20px;
  top: calc(50% - 10px);

  /* rotate "play" icon from > (right arrow) to down arrow */
  -webkit-transform: rotate(-90deg);
  -moz-transform:    rotate(-90deg);
  -ms-transform:     rotate(-90deg);
  -o-transform:      rotate(-90deg);
  transform:         rotate(-90deg);
}
.panel-heading[data-toggle="collapse"].collapsed:after {
  /* rotate "play" icon from > (right arrow) to ^ (up arrow) */
  -webkit-transform: rotate(90deg);
  -moz-transform:    rotate(90deg);
  -ms-transform:     rotate(90deg);
  -o-transform:      rotate(90deg);
  transform:         rotate(90deg);
}
&#13;
<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.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<!-- Accordion START -->
      <div class="panel-group" id="accordion">
        <div class="panel panel-default">
          <div class="panel-heading accordion-toggle collapsed" data-toggle="collapse" data-parent="#accordion" data-target="#collapseOne">
            <h4 class="panel-title">Test1</h4>

          </div>
          <div id="collapseOne" class="panel-collapse collapse">
            <div class="panel-body">
              <p>sadfsadfsdaf sadf</p>
            </div>
          </div>
        </div>
        <div class="panel panel-default">
          <div class="panel-heading accordion-toggle collapsed" data-toggle="collapse" data-parent="#accordion" data-target="#collapseTwo">
            <h4 class="panel-title">Test2</h4>

          </div>
          <div id="collapseTwo" class="panel-collapse collapse">
            <div class="panel-body">
<p>
Bla bla bla
</p>
            </div>
          </div>
        </div>
      </div>
      <!-- Accordion END -->
&#13;
&#13;
&#13;

答案 1 :(得分:1)

不需要字体(图标):

我提出了一个简单的解决方案:

.card-link::after {
    content: "";
    border-bottom: 0;
    border-top: .3em solid;
    border-right: .3em solid transparent;
    border-left: .3em solid transparent;
}

.card-link[aria-expanded="true"]::after {
    content: "";
    border-top: 0;
    border-bottom: .3em solid;
}