【问题标题】:Add padding to table (Maintain cell collapsed)向表格添加填充(保持单元格折叠)
【发布时间】:2017-08-13 16:08:32
【问题描述】:

我正在制作一个表格,每行之间都有一个边框,我一直在尝试编辑表格,以使行边框不会触及表格的外边框,我终生无法弄清楚我的。我觉得可能有一个我完全忽略了的解决方案。

我希望它是什么样子的:

现在的样子:

【问题讨论】:

  • 您还需要发布问题中的 HTML 和 CSS。

标签: html css border css-tables spacing


【解决方案1】:

IF边框设置为TD内部元素

tr td:first-child {
     padding-left:25px;
}
tr td:last-child {
     padding-right:25px;
}

否则一个不错的方法是在
灰色 DIV 中使用 透明表格 strong> 有你需要的填充

.tableContainer{
  padding:15px;
  position:relative;
  margin:0 auto;
  background:#353033;
  border:1px solid #000;
  box-shadow:0 5px 15px rgba(0,0,0,0.3);
}

table{
  color:#B3B3B3;
  table-layout:fixed;
  border-collapse:collapse;
  width:100%;
}

td, th{
  text-align:left;
  padding:5px 0;
  border-bottom: 1px solid #000;
}

/* --------------------- */

html, body{
  height:100%;
}
body{
  font: 16px/1 sans-serif;
  color: #fff;
/* Permalink - use to edit and share this gradient: http://colorzilla.com/gradient-editor/#6da5ce+0,9c7bac+50,ec8e99+100 */
background: #6da5ce; /* Old browsers */
background: -moz-linear-gradient(45deg,  #6da5ce 0%, #9c7bac 50%, #ec8e99 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left bottom, right top, color-stop(0%,#6da5ce), color-stop(50%,#9c7bac), color-stop(100%,#ec8e99)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(45deg,  #6da5ce 0%,#9c7bac 50%,#ec8e99 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(45deg,  #6da5ce 0%,#9c7bac 50%,#ec8e99 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(45deg,  #6da5ce 0%,#9c7bac 50%,#ec8e99 100%); /* IE10+ */
background: linear-gradient(45deg,  #6da5ce 0%,#9c7bac 50%,#ec8e99 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#6da5ce', endColorstr='#ec8e99',GradientType=1 ); /* IE6-9 fallback on horizontal gradient */
}
<div class="tableContainer">
  
  <table>
    <tr>
      <th>Title</th>
      <th>Title</th>
    </tr>
    <tr>
      <td>Text goes here</td>
      <td>and here also</td>
    </tr>
  </table>
  
</div>

【讨论】:

  • 非常感谢您的快速回复,灰色 DIV 内的透明表格正是我想要的。
  • @Wren 不客气。如果有帮助,添加一个演示......快乐编码。
  • @Wren 请在下次提问时尝试总是添加一些代码。一段代码通常比一张图片更能说明问题,它可以帮助人们帮助你。
  • 非常感谢,我很抱歉没有在我的帖子中包含代码,下次我会记住这一点。
  • @OrunBhuiyan 感谢您的赞许 :) 他可能是 SO 新手,他会及时学习
【解决方案2】:
.tableContainer {
    padding: 15px 0px;}
td, th {
    padding: 5px 10px;}

【讨论】:

  • 一些评论通常很受欢迎
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-02
  • 2019-12-08
  • 1970-01-01
  • 2012-01-26
  • 2011-11-20
相关资源
最近更新 更多