图标未向右对齐

时间:2018-11-28 20:02:15

标签: javascript css twitter-bootstrap

我正在使用bootstrap手风琴,我想在链接的右边有一个箭头,但是使用text-right来使右边的文本对齐是行不通的。你知道为什么吗?您还知道当用户单击链接时如何将真棒字体从<i class="fa fa-arrow-right"></i>切换到<i class="fa fa-arrow-down"></i>吗?

示例:http://jsfiddle.net/921bdzsu/

HTML:

<div class="container py-5">
  <div class="row">
    <div class="col">
      <div class="accordion" id="accordionExample">
        <div class="card">
          <div class="card-header" id="headingOne">
            <h5 class="mb-0">
              <a class="text-custom-blue-dark" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
                Title
              </a>
              <span class="ml-auto text-right"><i class="fa fa-arrow-right"></i></span>
            </h5>
          </div>

          <div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordionExample">
            <div class="card-body">
              <p class="faq-answer">
                Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
              </p>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

1 个答案:

答案 0 :(得分:4)

span元素默认为inline。因此它们占据了内容的确切宽度。您可以改用div,但它将放在下一行。

您最好的选择是使用定位或浮动元素。但是我觉得最干净的是使用flex

.mb-0 {
  display: flex;
  justify-content: space-between;
}

http://jsfiddle.net/921bdzsu/18/