>  기사  >  웹 프론트엔드  >  CSS 설정 테이블 둥근 테두리가 작동하지 않는 이유는 무엇입니까?

CSS 설정 테이블 둥근 테두리가 작동하지 않는 이유는 무엇입니까?

王林
王林원래의
2020-11-27 11:47:094660검색

CSS에서 테이블 둥근 테두리 설정이 작동하지 않는 이유는 border-collapse:collapse 속성과 border-radius 속성이 호환되지 않기 때문입니다. 올바른 방법은 [border-collapse: Separate;border-spacing:0]입니다.

CSS 설정 테이블 둥근 테두리가 작동하지 않는 이유는 무엇입니까?

이 글의 환경: windows10, css3, 이 글은 모든 브랜드의 컴퓨터에 적용 가능합니다.

원인 분석:

테이블에서 border-radius를 설정하면 작동하지 않는 것으로 나타났습니다. 이유는 border-collapse:collapse와 border-radius가 호환되지 않기 때문입니다.

(학습 영상 공유: css 영상 튜토리얼)

css:

border-collapse: separate;
border-spacing: 0;

코드 구현:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
#table_wrap > table {
font-size: 16px;
text-align: center;
margin: 0 auto;
border-collapse: separate;
border-spacing: 0;
border: 2px #000;
}
table thead tr,table tbody tr {
height: 50px;
line-height: 50px;
/*background-color: pink;*/
}
table tr th:first-child,table tr td:first-child {/*设置table左边边框*/
border-left: 2px solid #eaeaea;
}
table tr th:last-child,table tr td:last-child {/*设置table右边边框*/
border-right: 2px solid #eaeaea;
}
table tr td:first-child,
table tr td:nth-child(2),
table tr td:nth-child(3),
table tr td:last-child{/*设置table表格每列底部边框*/
border-bottom: 2px solid #eaeaea;
}
/*table tr:last-child td:first-child,
table tr:last-child td:nth-child(2),
table tr:last-child td:nth-child(3),
table tr:last-child td:last-child{/!*设置table表格最后一列底部边框*!/
border-bottom: 2px solid #000;
}*/
table tr th {
background: #eaeaea;
}
table tr:first-child th:first-child {
border-top-left-radius: 12px;
}
table tr:first-child th:last-child {
border-top-right-radius: 12px;
}
table tr:last-child td:first-child {
border-bottom-left-radius: 12px;
}
table tr:last-child td:last-child {
border-bottom-right-radius: 12px;
}
</style>
</head>
<body>
<div id="table_wrap">
<table width="800" cellspacing="0" cellpadding="0">
<thead>
<tr>
<th>头部1</th>
<th>头部2</th>
<th>头部3</th>
<th>头部4</th>
</tr>
</thead>
<tbody>
<tr>
<td>1内容1</td>
<td>1内容2</td>
<td>1内容3</td>
<td>1内容4</td>
</tr>
<tr>
<td>2内容1</td>
<td>2内容2</td>
<td>2内容3</td>
<td>2内容4</td>
</tr>
<tr>
<td>3内容1</td>
<td>3内容2</td>
<td>3内容3</td>
<td>3内容4</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>

구현 효과:

CSS 설정 테이블 둥근 테두리가 작동하지 않는 이유는 무엇입니까?

관련 권장 사항: CSS 튜토리얼

위 내용은 CSS 설정 테이블 둥근 테두리가 작동하지 않는 이유는 무엇입니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.