[英]HTML and CSS: how to make rounded corners on tables main corners
How am I supposed to exactly have 4 corners of this table to be rounded, I tried border-radius{ on table{ and it still doesnt work, and if do on the cells, it rounds every cells, i just want the main 4 corners of the table to be round?我应该如何准确地将这张桌子的 4 个角弄圆,我在桌子上尝试了边框半径 { 但它仍然不起作用,如果在单元格上这样做,它会环绕每个单元格,我只想要主要的 4 个角桌子要圆?
table{
/*removing the borders between the cells*/
border-collapse:collapse;
font-size: 14px;
/*table shadow*/
box-shadow: 0 6px 5px 1px rgba(0, 0, 0, 0.15);
margin-top: 40px ;
width: 70%;
height: 60%;
border-radius: 15px;
}
https://jsfiddle.net/qy4r3wn9/ https://jsfiddle.net/qy4r3wn9/
You likely have to add您可能必须添加
table { overflow: hidden; }
in order to let the (invisible) border actually snip off the content inside.为了让(不可见的)边框实际上剪掉里面的内容。 Currently, if you were to make the border visible (
border: 1px solid red;
) you'll see that your curved corners work just fine, but that the cell contents just stick out beyond the border.目前,如果您要使边框可见(
border: 1px solid red;
),您会看到您的弯角工作得很好,但单元格内容只是伸出边框之外。
You can use the first-child
and last-child selectors
, round the appropriate corners for the table cells in the four corners.您可以使用
first-child
和last-child selectors
,为四个角中的表格单元格圆角。
For this you have to give the cells in the first row a border-top
and in the first column a border-left
respectively.为此,您必须分别给第一行中的单元格一个
border-top
和第一列中的border-left
。
ALso set a border-right
and border-bottom
for your table cells ( td
and th
);还为表格单元格(
td
和th
)设置一个border-right
和border-bottom
;
You the below example:你下面的例子:
.custom-table{margin:30px;} table { border-collapse: separate; border-spacing: 0; min-width: 350px; } table tr th, table tr td { border-right: 1px solid #bbb; border-bottom: 1px solid #bbb; padding: 5px; } table tr th:first-child, table tr th:last-child{ border-top:solid 1px #bbb;} table tr th:first-child, table tr td:first-child { border-left: 1px solid #bbb; } table tr th:first-child, table tr td:first-child { border-left: 1px solid #bbb; } table tr th { background-color: #009879; color:#ffffff; text-align: left; } table.Info tr th, table.Info tr:first-child td { border-top: 1px solid #bbb; } /* top-left border-radius */ table tr:first-child th:first-child, table.Info tr:first-child td:first-child { border-top-left-radius: 6px; } /* top-right border-radius */ table tr:first-child th:last-child, table.Info tr:first-child td:last-child { border-top-right-radius: 6px; } /* bottom-left border-radius */ table tr:last-child td:first-child { border-bottom-left-radius: 6px; } /* bottom-right border-radius */ table tr:last-child td:last-child { border-bottom-right-radius: 6px; }
<div class="custom-table"> <table> <tr> <th>Job</th> <th>Salary</th> <th>Hours</th> <th>Location</th> <th>Experirence</th> </tr> <tr> <td>item1</td> <td>item2</td> <td>item3</td> <td>item4</td> <td>item5</td> </tr> <tr> <td>item1</td> <td>item2</td> <td>item3</td> <td>item4</td> <td>item5</td> </tr> <tr> <td>item1</td> <td>item2</td> <td>item3</td> <td>item4</td> <td>item5</td> </tr> </table> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.