如何使表格自动适应Bootstrap / CSS中的列宽

时间:2018-10-13 06:08:43

标签: css bootstrap-4

我想使Bootstrap中的表适合col-md-5列的宽度,但是实际上它会溢出到下一个表(即发票模板)。我试图使用类.table-responsive,但是它不起作用。我正在使用Bootstrap 4。

这是我的模板

{%  extends 'base.html' %}
{%  block content %}
<!DOCTYPE html>
<html lang="en">
    <body>
        <div class ="row">
            <div class="col-md-5">
                <div class="table-responsive">
                    <table class="table">
                      <thead>
                        <tr>
                          <th scope="col" >Photo</th>
                          <th scope="col">Name</th>
                          <th scope="col">ERP number</th>
                          <th scope="col">Unit</th>
                          <th scope="col">Price (USD)</th>
                          <th scope="col">Price (EUR)</th>
                        </tr>
                      </thead>
                      <tbody>
                        <tr>
                          <th scope="row">product.photo</th>
                          <td>product.item_name</td>
                          <td>product.erp_number</td>
                          <td>product.unit</td>
                          <td>product.price_usd</td>
                          <td>product.price_eur</td>
                        </tr>
                      </tbody>
                    </table>
                </div>
            </div>
            <div class="offset-md-5 col-md-7">
                {% include 'invoice.html' %}
            </div>
        </div>
    </body>
</html>
{%  endblock %}

已更新:

<html>
{% load staticfiles %}
{% load static i18n %}

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
  <title> Company| {% trans 'Witaj' %}</title>

    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
    <link href='http://fonts.font.im/css?family=Poiret+One|PT+Serif|PT+Sans|Pacifico|Satisfy' rel='stylesheet' type='text/css'>
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <link href="video-js.min.css" rel="stylesheet">
    <script src="video.min.js"></script>
    <script src="https://cdn.WebRTC-Experiment.com/RecordRTC.js"></script>
    <script src="wavesurfer.min.js"></script>
    <script src="wavesurfer.microphone.min.js"></script>
    <script src="videojs.wavesurfer.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
    <link href="{% static 'main/style.css' %}" rel="stylesheet" type="text/css"/>
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.2.0/css/all.css" integrity="sha384-hWVjflwFxL6sNzntih27bfxkr27PmbbK/iSvJ+a4+0owXq79v+lsFkW54bOGbiDQ" crossorigin="anonymous">

    {% block head_extra %} {% endblock head_extra %}

</head>

@Tieson T: 现在可以了。但是没有任何变化...我确实重新启动了本地服务器。

1 个答案:

答案 0 :(得分:-1)

请在.table-responsive { overflow-x: none; }

中更新您的CSS代码
.table-responsive {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    -ms-overflow-style: -ms-autohiding-scrollbar;
}