CSS表边框样式

时间:2016-03-18 17:23:17

标签: css html-table styling

我有一张桌子,我希望行/桌头是红色的,但是有一个略圆的角落比平直的边缘更平滑,但我还需要在标题之间留出宽度或者半径是没有意义的。只有我能想到的选项是为分隔符创建一个空的。但是更喜欢CSS修复。

代码

.restaurant {
width: 80%;
background-color: #FFFFFF;
color: #000000;
border: 1px solid #FFFFFF;
z-index: -1;
}
.restaurant tr {
width: 100%;
background-color: #FFFFFF;
border: 1px solid #FFFFFF;
border-spacing: 5px;
z-index: -1;
}
.restaurant td {
height: 100%;
background-color: #FFFFFF;
color: #000000;
border: 1px solid #FFFFFF;
z-index: -1;
}
.restaurant th {
line-height: 15px;
background-color: #DE0000;
color: #FFFFFF;
border: 5px solid #FFFFFF
border-spacing: 10px;
border-radius: 4px;
}

HTML

<table class="restaurant">
  <tr>
    <td colspan="2">

        <table class="restaurant-corners">
          <tr>
            <td width="10%">
              <img src="/css/images/menu-corner-top-left.png" class="corners">
            </td>
            <td width="80%">
            </td>
            <td width="10%">
              <img src="/css/images/menu-corner-top-right.png" class="corners" align="right">
            </td>
          </tr>
        </table>

       </td>
     </tr>
     <tr>
       <td colspan="2">

        <table class="restaurant-logo" cellspacing="0">
          <tr>
            <td colspan="3">
              <center><img src="/css/uncletoms.png"></center>
            </td>
          </tr>
          <tr>
            <th width="80%">
              <h2>Breakfast</h2>
            </th>
            <th width="20%">
              <h2>Drinks</h2>
            </th>
          </tr>
        </table>

可能需要更多信息。但我想确保我没有遗漏任何东西。

1 个答案:

答案 0 :(得分:0)

设计带圆角的桌子时,请勿使用border-collapse: collapse。 OP对红色行的请求是模糊的......红色边框?文本?背景?......需要具体细节。我们会将border-radius应用于表格的边框以及第一个和最后一个<th>边框。请参阅代码段

中的评论

&#13;
&#13;
section {
  padding: 20px 10px;
  width: 100%;
  height: auto;
  border-bottom: 3px ridge #FF6;
  margin: 0 5px 20px;
}
table.x {
  position: relative;
  padding: 0;
  box-shadow: 0 1px 9px 1px #ccc;
  /* This will round the outside border on all 4 corners */
  /* If you want only the head to have rounded corners uncomment *1* ruleset and remove or comment *2*/
  /* border-top-left-radius: 6px; 
     border-top-right-radius: 6px;
  */
  border-radius: 6px;
  margin: 20px auto;
  table-layout: fixed;
  width: 50%;
  height: 100%;
  max-height: 550px;
}
.x th {
  color: #FFF;
  background: #2C7EDB;
  padding: 10px;
  text-align: center;
  vertical-align: middle;
}
.x tr:nth-child(odd) {
  background-color: #333;
  color: #FFF;
}
.x tr:nth-child(even) {
  background-color: #D3E9FF;
  color: #333;
}
.x td {
  border-style: solid;
  border-width: 1px;
  border-color: #264D73;
  padding: 5px;
  text-align: left;
  vertical-align: top;
  position: relative;
}
/* Next 2 rulesets are used to create rounded corners to the inner borders of the head */

/* Remove or comment the last 2 rulesets if you don't want the bottom corners rounded */

.x thead th:first-child {
  border-top-left-radius: 6px;
}
.x thead th:last-child {
  border-top-right-radius: 6px;
}
.x tbody tr:last-child td:first-child {
  border-bottom-left-radius: 6px;
}
.x tbody tr:last-child td:last-child {
  border-bottom-right-radius: 6px;
}
&#13;
<section>
  <table class="x">
    <caption>table.x</caption>
    <thead>
      <tr>
        <th>Col1</th>
        <th>Col2</th>
        <th>Col3</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Content</td>
        <td>Content</td>
        <td>Content</td>
      </tr>
      <tr>
        <td>Content</td>
        <td>Content</td>
        <td>Content</td>
      </tr>
      <tr>
        <td>Content</td>
        <td>Content</td>
        <td>Content</td>
      </tr>
    </tbody>
  </table>
</section>
&#13;
&#13;
&#13;