I'd like to set a background and a rounded border on a <tbody/>
, such as
tbody { border-radius: 15px; border: 1px solid black; background: #ccf; }
However, when I try this in Codepen, the border and background color display, but the <tbody/>
still has square corners.
I'm able to work around this problem using a series of :last-child
and :first-child
selectors to apply the radius to individual td
s on the corners, as for example
tbody tr:first-child td:first-child { border-top-left-radius: 15px; }
This version does what I want (at least, under firefox) but also feels extremely verbose and hacky, a problem that'll only get worse when I add the prefixed versions for compatibility (-moz-
, -webkit-
etc), and support for <th/>
elements in addition to <td/>
. Is there a succinct, pure-css way of getting this behavior?
CSS Border Style The border-style property specifies what kind of border to display. The following values are allowed: dotted - Defines a dotted border
You can't put a border on the Tbody. You have to put the border-radius on the table element. This page should give you more information: codepen.io/anon/pen/xiaCc, found it on another question: stackoverflow.com/questions/19756736/…. It sets the borders of the bordering cells. (Not always desirable, but a work-around).
The effect depends on the border-color value The border-style property can have from one to four values (for the top border, right border, bottom border, and the left border). A dotted border.
CSS Border Color. The border-color property is used to set the color of the four borders. The color can be set by: name - specify a color name, like "red". Hex - specify a hex value, like "#ff0000".
Assuming you have collapsed the borders in the table, simply set display:block
on the tbody
and apply the border-radius
.
Codepen example
CSS
table {
width: 100%;
border-collapse: collapse;
display: block;
width: 600px;
}
tbody {
background: #ccf;
border: 1px solid black;
border-radius: 15px;
display: block;
}
th, td {
width: 200px;
}
td, th {
padding: 5px;
text-align: center;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With