首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >表格边框底部的间距

问表格边框底部的间距
EN

Stack Overflow用户
提问于 2018-11-14 06:50:39
回答 3查看 994关注 0票数 0

我有一个表格,我正在使用css来显示底部边框。

代码语言:javascript
复制
.inset {
    border-bottom: 1px solid #dadce0;
}

我希望在左边和右边有一些空间,就像使用<hr align="center" width="80%">一样,但我发现这是不可能的。

是否有我应该查看的属性,或者我应该研究的CSS技巧,以使表格保持完好,并能够看到居中但仅占表格宽度80%的底部边框?

EN

回答 3

Stack Overflow用户

发布于 2018-11-14 07:12:10

您可以将表格宽度设置为80% (左边距和右边距留出10% ),然后将整个表格居中:

​

代码语言:javascript
复制
.inset {
  border-bottom: 1px solid #dadce0;
  width: 80%;
  margin: 0 auto;
  background-color: coral;
}

.inset td {
  text-align: center;
}
代码语言:javascript
复制
<table class="inset">
  <tr>
    <td>Row 1 - Cell 1</td>
    <td>Row 1 - Cell 2</td>
    <td>Row 1 - Cell 3</td>
  </tr>
  <tr>
    <td>Row 2 - Cell 1</td>
    <td>Row 2 - Cell 2</td>
    <td>Row 2 - Cell 3</td>
  </tr>
  <tr>
    <td>Row 3 - Cell 1</td>
    <td>Row 3 - Cell 2</td>
    <td>Row 3 - Cell 3</td>
  </tr>
</table>

​

票数 1
EN

Stack Overflow用户

发布于 2018-11-14 06:58:26

如果你的底部边框在你的<table>标签之外,你可以将它包装在一个div中,显示为flex,居中对齐,然后给它一个80%的宽度。我想这会满足你的要求。如果这不起作用,你有没有尝试过仅仅使用边距属性?

例如,margin-left: 10%;。

如果不了解更多的html/css以及如何实现边框,就很难给你更多的指导。

票数 0
EN

Stack Overflow用户

发布于 2018-11-14 08:41:23

这个解决方案怎么样?它只是CSS。

​

代码语言:javascript
复制
table {
  width: 100%;
  position: relative;
  margin-bottom: 10px;
}

td {
  border: 1px solid grey;
  padding: 10px;
}

table:after {
  content: '';
  position: absolute;
  width: 80%;
  bottom: -10px;
  left: 10%;
  border-bottom: 2px solid red;
}
代码语言:javascript
复制
<table>
  <tr>
    <td>Apple</td>
    <td>Banana</td>
    <td>Carrot</td>
  </tr>
</table>

​

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53290697

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档