css - 表打破 max-width 的 100%

标签 css html-table

我有一个 {max-width: 100%} 的表格,它在 Chrome 中比其父容器宽 <div class="entry-content"> .我查看了一些关于 stackoverflow 的问答,但没有找到有效的解决方案。

实时代码在这里:http://vivesco-mhf.com.au/test2/有问题的表格在“我们提供的当前团体健身类(class)”下方 - 健身类(class)表,源代码的第 384 行。

A jsfiddle I couldn't replicate the problem with is here .我很想看到关于如何使用 jsfiddle 解决 CSS 问题的正式指南,这样像我这样的人就可以少打扰 stackoverflow 了。;-)

HTML:

<section id="container" class="two-columns-right">
  <div id="content" role="main">
    <div id="post-4818" class="post-4818 page type-page status-publish hentry">
      <div class="entry-content">
        <table>
          <tbody>
            <tr style="background-color: #333333; color: #ff9900;">
              <td width="10%" style="border-color: #c2c2c2;"></td>
              <td width="18%" style="border-color: #c2c2c2;"><strong><span style="color: #ff9900;">MON</span></strong></td>
              <td width="18%" style="border-color: #c2c2c2;"><strong><span style="color: #ff9900;">TUE</span></strong></td>
              <td width="18%" style="border-color: #c2c2c2;"><strong><span style="color: #ff9900;">WED</span></strong></td>
              <td width="18%" style="border-color: #c2c2c2;"><strong><span style="color: #ff9900;">THUR</span></strong></td>
              <td width="18%" style="border-color: #c2c2c2;"><strong><span style="color: #ff9900;">SAT</span></strong></td>
            </tr>
            <tr>
              <td width="10%" style="border-color: #c2c2c2;">&nbsp;<strong>05.30am</strong></td>
              <td width="18%" style="border-color: #c2c2c2;">Cardio Punch<br>
                St. Elizabeth’s Primary School, Hocking</td>
              <td width="18%" style="border-color: #c2c2c2;">FBI-A<br>
                St. Elizabeth’s Primary School, Hocking</td>
              <td width="18%" style="border-color: #c2c2c2;"></td>
              <td width="18%" style="border-color: #c2c2c2;">Cardio Punch<br>
                St. Elizabeth’s Primary School, Hocking</td>
              <td width="18%" style="border-color: #c2c2c2;"></td>
            </tr>
            <tr>
              <td width="10%" style="border-color: #c2c2c2;">&nbsp;<strong>06.30am</strong></td>
              <td width="18%" style="border-color: #c2c2c2;">FBI-A<br>
                St. Elizabeth’s Primary School<br>
                Hocking</td>
              <td width="18%" style="border-color: #c2c2c2;">Cardio Punch<br>
                St. Elizabeth’s Primary School<br>
                Hocking</td>
              <td width="18%" style="border-color: #c2c2c2;"></td>
              <td width="18%" style="border-color: #c2c2c2;">FBI-A<br>
                St. Elizabeth’s Primary School, Hocking</td>
              <td width="18%" style="border-color: #c2c2c2;"></td>
            </tr>
            <tr>
              <td width="10%" style="border-color: #c2c2c2;"><strong>07.00am</strong></td>
              <td width="18%" style="border-color: #c2c2c2;"></td>
              <td width="18%" style="border-color: #c2c2c2;"></td>
              <td width="18%" style="border-color: #c2c2c2;"></td>
              <td width="18%" style="border-color: #c2c2c2;"></td>
              <td width="18%" style="border-color: #c2c2c2;">Cardio Punch<br>
                St. Elizabeth’s Primary School, Hocking</td>
            </tr>
            <tr>
              <td width="10%" style="border-color: #c2c2c2;">&nbsp;<strong>05.00pm</strong></td>
              <td width="18%" style="border-color: #c2c2c2;"></td>
              <td width="18%" style="border-color: #c2c2c2;"></td>
              <td width="18%" style="border-color: #c2c2c2;">Cardio Punch<br>
                St. Elizabeth’s Primary School, Hocking</td>
              <td width="18%" style="border-color: #c2c2c2;"></td>
              <td width="18%" style="border-color: #c2c2c2;"></td>
            </tr>
            <tr>
              <td width="10%" style="border-color: #c2c2c2;"><strong>06.00pm</strong></td>
              <td width="18%" style="border-color: #c2c2c2;"></td>
              <td width="18%" style="border-color: #c2c2c2;"></td>
              <td width="18%" style="border-color: #c2c2c2;">FBI-A<br>
                St. Elizabeth’s Primary School, Hocking</td>
              <td width="18%" style="border-color: #c2c2c2;"></td>
              <td width="18%" style="border-color: #c2c2c2;"></td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>
  </div>
  <div id="secondary" class="widget-area sidey" role="complementary">
    <ul class="xoxo">
      <li id="search-5" class="widget-container widget_search">test sidebar</li>
    </ul>
  </div>
</section>  

CSS:

#container.two-columns-right #content {
    width: calc(100% - 310px);
    float: left;
}
#container.two-columns-right #secondary {
    width: 280px;
    float: right;
}
div.post, div.page, .yoyo > li {
    display: block;
    overflow: hidden;
    padding: 0;
    margin-bottom: 36px;
}
.entry-content {
    max-width: 100%;
}
.entry-content, .entry-summary {
    clear: both;
    padding-top: 8px;
    word-wrap: break-word;
}
#content table {
    max-width: 100%;
    border: 0;
    margin: 0 0px 24px 0;
    text-align: left;
    width: 100%;
    vertical-align: top;
    font-size: 16px;
    line-height: 0.9em;
    border-collapse: collapse;
    border-spacing: 0;
    display: table;
    border-collapse: collapse;
}
#content table td {
  word-wrap:break-word;
}
.entry-content, .entry-summary {
    word-wrap: break-word;
}

最佳答案

你的 <td> 的填充太大,因此单元格不够宽,无法正确显示您的内容。尝试减少填充,或减小字体大小。

你在 style.css 中写了第 892 行:

#content tr td { border-top: 1px solid transparent; padding: 6px 24px; }

尝试更改填充:padding: 6px 20px;或添加字体大小:font-size:15px;

关于css - 表打破 max-width 的 100%,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36689195/

相关文章:

html - 如何清除绝对定位的元素?

javascript - 有没有办法在 bootstrap-datetimepicker 中禁用月份/ View 模式按钮?

HTML & CSS : fullwidth element with first column fixed width and second column covering rest of the width

PHP编辑表A,显示到文本框然后保存到表B

html - Firefox 17.0.1 忽略字体粗细

CSS-hack - 在网站正文中添加 css

html - 如何在迭代中动态设置元素样式?

当分配为宽度 ="#%"时,表 > td 宽度的 HTML 5 验证错误

html - 如何在 bootstrap 中写一个包含表格的段落?

jQuery - 选择器