在Bootstrap中,在显示/没有可折叠元素的情况下显示表格相同
在Bootstrap 5中,我希望表显示以/没有可折叠元素的显示时显示相同的宽度。当前,当不显示可折叠元素时,它显示较短,这对用户很刺激。似乎希望它在设置宽度时考虑可折叠元素,但不知道该怎么做。
代码为
<div class="row justify-content-end">
<div class="col m-2">
<button id="show_credits_button" type="btn" class="btn btn-outline-primary m-1" data-bs-toggle="collapse" data-bs-target="#credits_id">
Show Credits
</button>
</div>
<div class="col-2 ms-auto m-2">
<span class="input-group">
<span for="filter" id="filterlabel" class="input-group-text">
Filter
</span>
<input type="text" id="filter" name="filter" onkeyup="filterOnly()" class="form-control">
</span>
</div>
</div>
和
<div class="row g-0">
<div class="col m-2">
<table class="table table-sm table-hover">
<tbody>
<tr>
<td colspan="5">
<b>
Disc 1
</b>
</td>
</tr>
<tr class="song_id">
<td>
1
</td>
<td>
<div>
<label class="h6">
Take On Me
</label>
</div>
<div class="collapse" id="credits_id">
<div class="lh-1">
<label class="small figure-caption">
Performed by
</label>
<span>
<a href="/artist.start?id=70bd15b0-c1b3-4f0d-b275-c1f8553ae1f6&title=a-ha&cid=0$=Artists$19126" class="small figure-caption">
a-ha
</a>
<label class="small figure-caption">
</label>
</span>
</div>
</tr>
</tbody>
</table>
</div>
</div>
In bootstrap 5 I would like table to be displayed same width when displaying with/without collapsible elements. Currently it display shorter when not displaying the collapsible elements, which is irritating for user. Seems want it to consider collapsible elements when setting width but don't know how to do this.
Code is
<div class="row justify-content-end">
<div class="col m-2">
<button id="show_credits_button" type="btn" class="btn btn-outline-primary m-1" data-bs-toggle="collapse" data-bs-target="#credits_id">
Show Credits
</button>
</div>
<div class="col-2 ms-auto m-2">
<span class="input-group">
<span for="filter" id="filterlabel" class="input-group-text">
Filter
</span>
<input type="text" id="filter" name="filter" onkeyup="filterOnly()" class="form-control">
</span>
</div>
</div>
and
<div class="row g-0">
<div class="col m-2">
<table class="table table-sm table-hover">
<tbody>
<tr>
<td colspan="5">
<b>
Disc 1
</b>
</td>
</tr>
<tr class="song_id">
<td>
1
</td>
<td>
<div>
<label class="h6">
Take On Me
</label>
</div>
<div class="collapse" id="credits_id">
<div class="lh-1">
<label class="small figure-caption">
Performed by
</label>
<span>
<a href="/artist.start?id=70bd15b0-c1b3-4f0d-b275-c1f8553ae1f6&title=a-ha&cid=0$=Artists$19126" class="small figure-caption">
a-ha
</a>
<label class="small figure-caption">
</label>
</span>
</div>
</tr>
</tbody>
</table>
</div>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
与@cervus的答案类似,您正在遇到此问题,因为不滚动会更改元素的宽度,而元素的宽度没有任何约束,可以解决此问题,要解决此问题,您想将强制宽度设置为使用Bootstrap进行此操作。可以使用行和cols,如图所示:
https://codepen.io/rokasrudys/rokasrudys/pen/pen/pen/ojvrwdq
Similar to the answer by @Cervus, you are having this issue as uncollapsing changes the width of the element which has no constraints reshifting things around, to fix this you'd want to set a forced width to the column to do this with bootstrap you can use rows and cols as shown:
https://codepen.io/rokasrudys/pen/OJvRwdQ
在这里您
添加ID(例如,
set_width
)和setwidth:500px!estignts;
。html:
css:
让我知道这是否有帮助。
Here you go...
Add an id (e.g.,
set_width
) and setwidth: 500px !important;
.HTML:
CSS:
Let me know if this is helpful.