在Bootstrap中,在显示/没有可折叠元素的情况下显示表格相同

发布于 2025-02-11 10:19:04 字数 2908 浏览 0 评论 0原文

在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&amp;title=a-ha&amp;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>

collapsible hidden
collapsible displayed

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我不是你的备胎 2025-02-18 10:19:04

与@cervus的答案类似,您正在遇到此问题,因为不滚动会更改元素的宽度,而元素的宽度没有任何约束,可以解决此问题,要解决此问题,您想将强制宽度设置为使用Bootstrap进行此操作。可以使用行和cols,如图所示:

https://codepen.io/rokasrudys/rokasrudys/pen/pen/pen/ojvrwdq

<div class="row g-0">
<table class="table table-sm table-hover">
  <thead>
    <tr>
      <td colspan="5">
        <b>
          Disc 1
        </b>
      </td>
    </tr>
  </thead>
  <tbody>
    <tr class="song_id">
      <td class="col-1">1</td>
        <td class="col-8 col-sm-6 align-start">
          <label class="h6 ">
            Take On Me
          </label>
          <div class="collapse" id="credits_id">
            <div class="lh-1">
              <label class="small figure-caption">
                Performed by
              </label>
              <span>
                <a href="" class="small figure-caption">
                  a-ha
                </a>
                <label class="small figure-caption">

                </label>
              </span>
            </div>
          </div>
        </td>
        <td class='col-1' >
          time
        </td>
        <td class='col-1'>
          <button>queue </button>
        </td>
      </tr>
    </tbody>
  </table>
</div>

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

<div class="row g-0">
<table class="table table-sm table-hover">
  <thead>
    <tr>
      <td colspan="5">
        <b>
          Disc 1
        </b>
      </td>
    </tr>
  </thead>
  <tbody>
    <tr class="song_id">
      <td class="col-1">1</td>
        <td class="col-8 col-sm-6 align-start">
          <label class="h6 ">
            Take On Me
          </label>
          <div class="collapse" id="credits_id">
            <div class="lh-1">
              <label class="small figure-caption">
                Performed by
              </label>
              <span>
                <a href="" class="small figure-caption">
                  a-ha
                </a>
                <label class="small figure-caption">

                </label>
              </span>
            </div>
          </div>
        </td>
        <td class='col-1' >
          time
        </td>
        <td class='col-1'>
          <button>queue </button>
        </td>
      </tr>
    </tbody>
  </table>
</div>
执笔绘流年 2025-02-18 10:19:04

在这里您

添加ID(例如,set_width)和set width:500px!estignts;

html:

<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 id="set_width">
                        <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>
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</div>

css:

#set_width {
  width: 500px !important;
}

让我知道这是否有帮助。

Here you go...

Add an id (e.g., set_width) and set width: 500px !important;.

HTML:

<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 id="set_width">
                        <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>
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</div>

CSS:

#set_width {
  width: 500px !important;
}

Let me know if this is helpful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文