html - 在 Bootstrap 手风琴中左右对齐文本
问题描述
我在 Bootstrap 中有一个手风琴,但我想要左侧的文本,但也需要右侧的文本,右侧是控制折叠的箭头:
我有:
<div class="accordion accordion-flush" id="accordion-tracks">
<div class="accordion-item">
<h2 class="accordion-header" id="heading-1">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapse-1" aria-expanded="false" aria-controls="collapse-1">
<div class="d-flex justify-content-between w-100">
<div>1. The Eater Of Dreams</div>
<div style="padding-right: 10px;">0:52</div>
</div>
</button>
</h2>
....
我不确定是否button
建议在 a 中执行此操作。我也尝试过span
and float-start
,float-end
但这似乎不起作用。
谢谢
解决方案
从Bootstrap 文档中的示例开始,您只需要做两件事:
- 在按钮标签内添加几个容器标签以创建两列。
- 为按钮添加一个类并将其设置为网格。
您最终将在网格内得到 3 列,一列用于标题,一列用于时间,一列用于箭头(这是一个伪元素)
button.acc-btn {
/* create a grid */
display: grid;
/* create colums. 1fr means use available space */
grid-template-columns: 1fr max-content max-content;
align-items: center;
grid-gap: 10px;
}
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" />
<div class="accordion" id="accordionExample">
<div class="accordion-item">
<h2 class="accordion-header" id="headingOne">
<button class="acc-btn accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
<span class="title">
1. The Eater Of Dreams
</span>
<span class="time">
0:52
</span>
</button>
</h2>
<div id="collapseOne" class="accordion-collapse collapse show" aria-labelledby="headingOne" data-bs-parent="#accordionExample">
<div class="accordion-body">
<strong>This is the first item's accordion body.</strong> It is shown by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and
hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header" id="headingOne">
<button class="acc-btn accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
<span class="title">
1. The Eater Of Dreams
</span>
<span class="time">
0:52
</span>
</button>
</h2>
<div id="collapseOne" class="accordion-collapse collapse show" aria-labelledby="headingOne" data-bs-parent="#accordionExample">
<div class="accordion-body">
<strong>This is the first item's accordion body.</strong> It is shown by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and
hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
</div>
</div>
</div>
</div>
推荐阅读
- angular - 如何根据单元格中的值更改 mat-table 中 mat-icon 的颜色
- python - 为什么我的基本指数函数不起作用?
- github - 如何让我的 Heroku 应用程序可供拥有该链接的其他人查看?
- regex - 如何在提供值之前删除所有内容
- regex - 如何将这个正则表达式转换为 Megaparsec 解析器而不造成混乱?
- authentication - 带 Google 身份验证的 Keycloak - 用户名或密码无效
- python - FuncAnimation 未使用 Jupyter 笔记本中的自定义 event_source 进行更新
- php - 在 PHP 中连接到 APNS 服务器时发送 Apple 推送通知的问题
- powershell - 使用服务帐户运行时出现 Powershell Word SaveAs 命令错误
- python - ValueError:没有为任何变量提供渐变 - Keras Tensorflow 2.0