chan

朝生暮死不足笑 但悲百年不足道

【Bootstrap】栅格系统中某个字段内容过长导致的页面布局异常及处理


如上图所示,过长的文本,导致某个字段占用过长的宽度,进而导致后面的字段布局异常。

—————————————————————————————-

前端代码如下图所示

      <table class="table table-bordered">
        <thead>
          <tr>
            <th>ID</th>
            <th>游戏名称</th>
            <th>面额大小</th>
              <th>充值链接</th>

              <th>客户名称</th>
              <th>入库人</th>
              <th>订单号</th>
          <th>订单创建时间</th>
               {% if request.path_info == '/game/out/list/' %}
              <th>订单结束时间</th>
                  <th>订单状态</th>
                  <th>出库人</th>
              {% endif %}
              <th>操作</th>
          </tr>
        </thead>
        <tbody>
        {% for obj in queryset %}
            <tr>
            <th>{{ obj.id }}</th>
            <td>{{ obj.get_game_name_display }}</td>
            <td>{{ obj.denomination }}</td>
            <td>
                <span id="charge_link_{{ obj.id }}">{{ obj.charge_link }}</span>
                <button class="btn btn-primary btn-xs" onclick="copyToClipboard('{{ obj.id }}')">复制</button>
            </td>

            <td>{{ obj.consumer }}</td>
            <td>{{ obj.in_storage_person }}</td>
            <td>{{ obj.order_number }}</td>
            <td>{{ obj.order_create_time|date:"Y-m-d H:i:s" }}</td>
            {% if obj.order_finish_time %}
                <td>{{ obj.order_finish_time|date:"Y-m-d H:i:s" }}</td>
                <td>{{ obj.get_order_status_display }}</td>
                <td>{{ obj.out_storage_person }}</td>
            {% endif %}

            <td>
             {% if request.path_info != '/game/out/list/' %}
                <a class="btn btn-primary btn-xs" href="/game/edit/{{ obj.id }}/">编辑</a>
                <a class="btn btn-danger btn-xs" href="/game/delete/{{ obj.id }}/">删除</a>
                 {% if not request.user.usertype == 3 %}
                <a class="btn btn-danger btn-xs" href="/game/out/{{ obj.id }}/">出库</a>
                     {% endif %}
            {% endif %}
             {% if request.path_info == '/game/out/list/' %}
                  {% if not request.user.usertype == 3 %}
            <a class="btn btn-danger btn-xs" href="/game/out/reout/{{ obj.id }}/">回调</a>
                      {% endif %}
            {% endif %}
            </td>

        {% endfor %}
        </tbody>
      </table>

——————————————————————————————————–

按照如下修改

在 CSS 中使用 text-overflow: ellipsis 使链接截断显示,用户仍然可以复制完整内容。

<td>
    <div class="text-truncate" style="max-width: 180px;" title="{{ obj.charge_link }}">
        <span id="charge_link_{{ obj.id }}">{{ obj.charge_link }}</span>
    </div>
    <button class="btn btn-primary btn-xs" onclick="copyToClipboard('{{ obj.id }}')">复制</button>
</td>

———————————————————-

css按照如下修改

.text-truncate {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

——————————————————-

结果如下图所示

————————————–

完美解决

评论
还没有评论
    发表评论 说点什么