0

I have little problem with my table. It is stylized by classes. One for TABLE that makes rounded corners and changes background to grey. The other is to make rest of the table white and I assign it to TBODY. After second class is asigned, bottom-left and bottom-right corners are no longer rounded.

<table align=center class="grey">
  <thead>
    <tr height=50>
      <th>header</th>
      <th>header</th>
    </tr>
  </thead>
  <tbody class="white">
    <tr height=50>
      <td>row two</td>
      <td>row two</td>
    </tr>

    <tr height=50 class="white">
      <td>row three</td>
      <td>row three</td>
    </tr>
  </tbody>
</table>

body {
  background: #000;
}

table.grey {
    background: #F6F2F5;
    border: 3px solid #FFF;
    text-align: center;
    width: 80%;
    padding: 15px;
    border-collapse: collapse;
    border-left: 0;
    border-right: 0;
    border-radius: 10px;
    border-spacing: 0px;
}
.white {
  background: #FFF;
  color: #000;
  padding: 50px;
  border-bottom-left-radius: 10px;
  border-bottom-right-radius: 10px;
}

Giving class to TR of each row gives same result as to TBODY. I'm dumb. https://jsfiddle.net/2tm4z90b/8/

1
  • tbody cannot be styled, it is not supposed to be seen, it is a semantic wrapper. Commented Nov 14, 2022 at 8:59

2 Answers 2

2

tbody cannot really be styled , it is part of the structure of a table and is not supposed to be seen, nor styled unless you reset its display but that will break your table-layout.

Option are

  • to set the radius only on the table and use overflow.
  • fake the border via a box-shadow if needed, so it follows the rounded shape

Possible example:

body {
  background: #000;
}

table.grey{
    margin-top:3em;
    background: gray;
    box-shadow:0 0 0 3px red;/* instead border */
    text-align: center;
    width: 80%;
    padding: 15px;
    border-collapse: collapse;
    border-left: 0;
    border-right: 0;
    border-radius: 10px;
    border-spacing: 0px;
    overflow:hidden; /* hide overflowing cells */
}
.white tr {
  background: #bee;
  color: #000;
  padding: 50px;  
}
<table align=center class="grey">
  <thead>
    <tr height=50>
      <th>header</th>
      <th>header</th>
    </tr>
  </thead>
  <tbody class="white">
    <tr height=50>
      <td>row two</td>
      <td>row two</td>
    </tr>

    <tr height=50>
      <td>row three</td>
      <td>row three</td>
    </tr>
  </tbody>
</table>

Sign up to request clarification or add additional context in comments.

1 Comment

overflow:hidden made it work with my code. Didnt even need to use box-shadow. Thank you, I owe you man ^^
2

Like this.

table {
  border-radius: 5px;
  border: 1px solid black;
}
table thead {
    background: gray;
}
<table align=center class="grey">
  <thead>
    <tr height=50>
      <th>header</th>
      <th>header</th>
    </tr>
  </thead>
  <tbody class="white">
    <tr height=50>
      <td>row two</td>
      <td>row two</td>
    </tr>

    <tr height=50 class="white">
      <td>row three</td>
      <td>row three</td>
    </tr>
  </tbody>
</table>

3 Comments

It's not the only table in here, so cant use your css
You can use it for some tables or one table. Just adjust the css width .class , #id or table in an element.
You fixed code that was in conflict by deleting it. That's not fix at all.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.