【问题标题】:How to break long words in CSS and HTML如何在 CSS 和 HTML 中打断长词
【发布时间】:2019-02-07 11:43:49
【问题描述】:

我在我的 Python 模板中使用了断字。所以基本上我正在将html转换为pdf。所以一切正常。但长话并没有在我的桌子上分解。请帮我分解td 中的长词。我已经做了td 课程,我试图打破文字。但它似乎不起作用。请帮忙。

@page {
  size: A4;
  margin: 1cm;
}

.table,
td,
th {
  border: 1px solid #ddd;
  text-align: left;
}

.table {
  border-collapse: collapse;
  width: 100%;
  table-layout: fixed;
}

.table th,
td {
  padding: 5px;
  text-align: center;
}

.td {
  word-wrap: break-word;
  overflow-wrap: break-word
}

.list-group h3 {
  font-size: 3em;
}

.list-group p {
  font-size: 1em;
}

.table1 {
  width: 100%;
  max-width: 100%;
  margin-bottom: 5px;
  background-color: #fff;
  border: none;
  text-align: center;
}
<div class="container">
  <div class="card">
    <table class="table1">
      <td><img src="https://mytabtime.com/wp-content/uploads/2018/09/myTABtime-com-logo-240.png" alt="logo" /></td>
      <td>
        <div class="list-group">
          <h3>Company Report</h3>
          <p>Date - {% now "jS F Y H:i" %}</p>
        </div>
      </td>
    </table>
    <br/>
    <table class="table">
      <thead>
        <tr>
          <th>#</th>
          <th>Company Name</th>
          <th>Company Email</th>
          <th>Count Of Total Users</th>
          <th>Created Date</th>
          <th>Current Monthly Payment</th>
          <th>Is TABopts Customer</th>
          <th>Status</th>
        </tr>
      </thead>
      <tbody>
        {% if companies %} {% for company in companies %}
        <tr>
          <td class="td">{{ forloop.counter }}</td>
          <td>{{ company.company_name }}</td>
          <td class="td">{{ company.company_email }}afsdasdfasdfasdf</td>
          <td class="td">{{ company.number_of_company_users }}</td>
          <td class="td">{{ company.company_created |date:"M d, Y" }}</td>
          <td class="td">{{ company.company_monthly_payment }}</td>
          <td class="td">{{ company.company_tab_opts }}</td>
          <td class="td">{{ company.company_status }}</td>
        </tr>
        {% endfor %} {% endif %}
      </tbody>
    </table>
  </div>
</div>

【问题讨论】:

标签: html css


【解决方案1】:

@page {
  size: A4;
  margin: 1cm;
}

.table,
td,
th {
  border: 1px solid #ddd;
  text-align: left;
}

.table {
  border-collapse: collapse;
  width: 100%;
  table-layout: fixed;
}

.table th,
td {
  padding: 5px;
  text-align: center;
}

.td {
  word-break: break-word;
}

.list-group h3 {
  font-size: 3em;
}

.list-group p {
  font-size: 1em;
}

.table1 {
  width: 100%;
  max-width: 100%;
  margin-bottom: 5px;
  background-color: #fff;
  border: none;
  text-align: center;
}
<div class="container">
  <div class="card">
    <table class="table1">
      <td><img src="https://mytabtime.com/wp-content/uploads/2018/09/myTABtime-com-logo-240.png" alt="logo" /></td>
      <td>
        <div class="list-group">
          <h3>Company Report</h3>
          <p>Date - {% now "jS F Y H:i" %}</p>
        </div>
      </td>
    </table>
    <br/>
    <table class="table">
      <thead>
        <tr>
          <th>#</th>
          <th>Company Name</th>
          <th>Company Email</th>
          <th>Count Of Total Users</th>
          <th>Created Date</th>
          <th>Current Monthly Payment</th>
          <th>Is TABopts Customer</th>
          <th>Status</th>
        </tr>
      </thead>
      <tbody>
        {% if companies %} {% for company in companies %}
        <tr>
          <td class="td">{{ forloop.counter }}</td>
          <td class="td">{{ company.company_name }}</td>
          <td class="td">{{ company.company_email }}afsdasdfasdfasdf</td>
          <td class="td">{{ company.number_of_company_users }}</td>
          <td class="td">{{ company.company_created |date:"M d, Y" }}</td>
          <td class="td">{{ company.company_monthly_payment }}</td>
          <td class="td">{{ company.company_tab_opts }}</td>
          <td class="td">{{ company.company_status }}</td>
        </tr>
        {% endfor %} {% endif %}
      </tbody>
    </table>
  </div>
</div>

尝试在 td 上使用 word-break: break-word;,并将缺少的 .td 类添加到 &lt;td&gt; 元素。

【讨论】:

    【解决方案2】:

    使用 css 属性 'word-break' 而不是 word-wrap。

    Read this for more info

    【讨论】:

      猜你喜欢
      • 2013-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-19
      • 2017-02-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多