내 테이블의 일부 행 사이에 선을 만들고 싶지만 모두는 아닙니다. 여러 가지 방법을 시도했지만 항상 이상한 일이 발생합니다. 지금까지 내가 가진 것은 다음과 같습니다.
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css">
</head>
<body>
<table width=100%>
<tr id="border-top" align="center"><th>A</th><td>B</td></tr>
<tr id="border-top" align="center"><th>1</th><td>11</td></tr>
<tr align="center"><th>2</th><td>12</td></tr>
<tr id="border-top" align="center"><th>3</th><td>13</td></tr>
<tr id="border-top" align="center"><th>4</th><td>14</td></tr>
<tr align="center"><th>5</th><td>15</td></tr>
<tr id="border-top" align="center"><th>6</th><td>16</td></tr>
<tr id="border-top" align="center"><th>7</th><td>17</td></tr>
</table>
</body>
</html>
그리고이 CSS :
#border-top{
text-align:center;
border-top:1px solid black;
display:block;
}
하지만 내 출력은 다음과 같이 보입니다. display:block;
또는 그것없이 이렇게 :
첫 번째 그림과 같이 선이 거기에 있기를 바랍니다. 하지만 두 번째 그림과 같이 모두 제대로 정렬되기를 바랍니다. 대신 어떻게해야합니까?
미리 감사드립니다!
첫째, id
속성은 페이지에서 고유해야합니다. 즉, id
페이지 당 하나 (동일한 값) 만 있어야 합니다. 사용 class
(같은 CSS를 공유하는, 즉 여러 요소를이 특정 유스 케이스 대신 class
)
둘째, tr
자체는 CSS로 장식되지 않습니다. th
s와 s를 장식 해보세요 td
.
CSS 규칙에 다음을 추가하면됩니다.
.border-top td, .border-top th{...}
아래 예를 참조하십시오 .
.border-top td, .border-top th {
border-top: 1px solid green;
}
table {
border-spacing: 0px;
}
<table width="100%">
<tr class="border-top" align="center">
<th>A</th>
<td>B</td>
</tr>
<tr class="border-top" align="center">
<th>1</th>
<td>11</td>
</tr>
<tr align="center">
<th>2</th>
<td>12</td>
</tr>
<tr class="border-top" align="center">
<th>3</th>
<td>13</td>
</tr>
<tr class="border-top" align="center">
<th>4</th>
<td>14</td>
</tr>
<tr align="center">
<th>5</th>
<td>15</td>
</tr>
<tr class="border-top" align="center">
<th>6</th>
<td>16</td>
</tr>
<tr class="border-top" align="center">
<th>7</th>
<td>17</td>
</tr>
</table>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다