javascript - 图标未右对齐

标签 javascript css twitter-bootstrap

我正在使用 bootstrap Accordion ,我想在链接的右边有一个箭头,但是用 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>

最佳答案

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

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

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

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

关于javascript - 图标未右对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53527252/

相关文章:

javascript - Object.create(Object.prototype) , Object.create(Object) 和 Object.create(null) 之间的区别

Javascript 执行问题

html - 将一个 div 标签放在其他标签之上,并将位置与另一个 div 相关联

HTML/CSS : Display: block with a float or inline-block

jquery - 如何在小屏幕上将 Bootstrap 导航选项卡显示为可折叠按钮?

twitter-bootstrap - 你怎么能在 Bootstrap 中有一个导航栏拆分按钮下拉组件?

javascript - 升级到rails 3.2.9后无法专注于输入

javascript - 逐一淡入div内容

css - 带有 Bootstrap 颜色选择器的 Kendo UI 窗口,窗口总在最前面

javascript - Ionic Accordion 中断的切换功能。不展开第二个 Accordion 。(传递的数据太多?)