html - 从表中的每 2n 个元素中删除边框间距

标签 html css angular

我有一个看起来像这样的表:

enter image description here

每一行都有一个隐藏的详细信息字段:

enter image description here

所以我想从行及其详细信息行中删除边框间距。我该怎么做?

这是我的 HTML:

<table class="table message-table">
    <thead>
        <tr>
            <th>Title</th>
            <th>Date</th>
            <th>Action</th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        <ng-container *ngFor="let message of messages | paginate: config">
            <tr>
                <td>{{message.title}}</td>
                <td>{{message.created | date:'longDate'}}</td>
                <td (click)="message.collapsed = !message.collapsed; makeMessageSeen(message);" [attr.aria-expanded]="!message.collapsed" aria-controls="collapseExample">{{message.collapsed ? 'More' : 'Less'}}</td>
                <td></td>
            </tr>
            <tr id="collapseExample" [ngbCollapse]="message.collapsed">
                <td>{{message.text}}</td>
                <td colspan="3"></td>
            </tr>
        </ng-container>
    </tbody>
</table>

这是我的 SCSS:

.messages {
    background-color: $color-background-main;
    min-height: 17rem;
    overflow-x: auto;
    padding-top: 2rem;

    .message-table {
        border-collapse: separate;
        border-spacing: 0 0.4rem;

        thead {
            th {
                border: none;
                font-size: 0.6rem;
                color: #9b9b9b;
                text-transform: uppercase;
                padding-top: 0;
                padding-bottom: 0;

                &:first-child {
                    width: 70%;
                    padding-left: 1rem;
                }
            }
        }
    }

    tbody {

        tr {
            box-shadow: $main-shadow;
            background-color: white;

            &.selected {
                box-shadow: $shadow-selected;
            }

            td:first-child {
                padding-left: 1rem;
            }
        }

        td {
            background-color: white;
            border: none;
            padding-top: 0;
            padding-bottom: 0;
            padding-right: 0;
            height: 2.5rem;
            vertical-align: middle;
            table-layout: fixed;

            &:first-child {
                border-top-left-radius: 5px;
                border-bottom-left-radius: 5px;
            }

            &:last-child {
                border-top-right-radius: 5px;
                border-bottom-right-radius: 5px;
                padding-right: 0;
                width: 2rem;
            }
        }
    }
}

我该如何解决这个问题?我已经尝试将 tr 设置为顶部边框,但没有任何反应......我的问题还有哪些其他解决方案?

更新 1

添加一个简单示例的代码笔:https://codepen.io/anon/pen/prxgOe

更新 2

我只想删除标题和详细信息 tr 元素之间的间距!

最佳答案

这是使用边框的快速修复。

table {
  border-collapse: collapse;
  border-spacing: 0 0.4rem;
}

tr {
  background-color: #ccc;
}

.title {
  border-top: 5px solid #fff;
}

.details {
  /*   display: none; */
}
<table>
  <thead>
    <tr>
      <th>Title</th>
      <th>Created</th>
      <th>Action</th>
    </tr>
  </thead>
  <tbody>
    <tr class="title">
      <td>title1</td>
      <td>2017-01-01</td>
      <td>More</td>
    </tr>
    <tr class="details">
      <td>this is text1</td>
      <td colspan="2"></td>
    </tr>

    <tr class="title">
      <td>title2</td>
      <td>2017-01-01</td>
      <td>More</td>
    </tr>
    <tr class="details">
      <td>this is text2</td>
      <td colspan="2"></td>
    </tr>

    <tr class="title">
      <td>title3</td>
      <td>2017-01-01</td>
      <td>More</td>
    </tr>
    <tr class="details">
      <td>this is text3</td>
      <td colspan="2"></td>
    </tr>
  </tbody>
</table>

关于html - 从表中的每 2n 个元素中删除边框间距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45912998/

相关文章:

angular - 如何创建自定义响应式表单元素?

angular - 当用户离线并返回在线时,如何使我的 ionic 清新器正常工作?

javascript - 如果用户单击图标图像,如何显示 bsDatePicker 弹出窗口

html - 设置 flex 元素之间的垂直间隙

javascript - 自定义创建的下拉 onclick 函数未触发

html - 没有间隙的并排图像?

html - 移除光标后保留Transition效果

php - 在 html 中添加多行时表单的输出给我 Word "ARRAY"

css - 是否有 "previous sibling"选择器?

html - 为什么 Flexbox 中的强文本表现为列?