HTML/CSS

[HTML] Table tr, th, td 배경 색상 지정방법 | bgcolor | background-color


[HTML] Table tr, th, td 배경 색상 지정방법 | bgcolor | background-color


  2023-05-12  1278 View 공개

HTML 테이블의 th, tr, td 요소의 배경색을 지정하려면 CSS(Cascading Style Sheets)를 사용해야 한다.
CSS는 웹 페이지의 스타일을 결정하는 언어이다.

다음은 HTML 테이블의 th, tr, td 요소에 배경색을 지정하는 방법의 예이다.

 Inline CSS

각 HTML 요소에 직접 스타일을 적용한다.
이 방법은 유지 관리가 어렵다는 단점이 있다.
HTML
<table>
   <tr style='background-color: lightblue;'>
      <th style='background-color: lightgreen;'>Header</th>
      <td style='background-color: lightpink;'>Data</td>
   </tr>
</table>

 Internal CSS

HTML 문서의 <head> 영역에 <style> 태그를 사용해 CSS를 적용한다.

HTML
<html>
  <head>
    <style>
      th { background-color: lightgreen; }
      tr { background-color: lightblue; }
      td { background-color: lightpink; }
    </style>
  </head>
  <body>
     <table>
        <tr>
          <th>Header</th>
          <td>Data</td>
        </tr>
     </table>
  </body>
</html>

 External CSS

별도의 CSS 파일에 스타일을 정의하고 HTML 문서에 링크한다.
이 방법은 여러 HTML 문서에서 동일한 스타일을 재사용할 수 있어 유지 관리가 편리하다.
HTML
<!-- In your HTML file -->
  <html>
    <head>
      <link rel='stylesheet' type='text/css' href='styles.css'>
    </head>
    <body>
      <table>
        <tr>
          <th>Header</th>
          <td>Data</td>
        </tr>
      </table>
     </body>
  </html>
 
CSS
/* In your CSS file (styles.css) */
th { background-color: lightgreen; }
tr { background-color: lightblue; }
td { background-color: lightpink; }

이와 같이 CSS를 사용하면 웹 페이지의 각 요소에 스타일을 적용할 수 있다.
이렇게 하는 것이 HTML 태그의 bgcolor 속성을 사용하는 것보다 권장되는 방법이다, bgcolor는 HTML 4.01에서는 지원되지만, HTML5에서는 더 이상 지원되지 않는다.

HTML 테이블의 th, tr, td 요소의 배경색을 지정하려면 CSS(Cascading Style Sheets)를 사용해야 한다. CSS는 웹 페이지의 스타일을 결정하는 언어이다.

다음은 HTML 테이블의 th, tr, td 요소에 배경색을 지정하는 방법의 예이다.

  1. Inline CSS: 각 HTML 요소에 직접 스타일을 적용한다. 이 방법은 유지 관리가 어렵다는 단점이 있다.

    html
    <table>
       <tr style='background-color: lightblue;'>
          <th style='background-color: lightgreen;'>Header</th>
          <td style='background-color: lightpink;'>Data</td>
       </tr>
    </table>
  2. Internal CSS: HTML 문서의 <head> 영역에 <style> 태그를 사용해 CSS를 적용한다.

    html
    <html>
      <head>
        <style>
          th { background-color: lightgreen; }
          tr { background-color: lightblue; }
          td { background-color: lightpink; }
        </style>
      </head>
      <body>
         <table>
            <tr>
              <th>Header</th>
              <td>Data</td>
            </tr>
         </table>
      </body>
    </html>
  3. External CSS: 별도의 CSS 파일에 스타일을 정의하고 HTML 문서에 링크한다. 이 방법은 여러 HTML 문서에서 동일한 스타일을 재사용할 수 있어 유지 관리가 편리하다.

    html
    <!-- In your HTML file -->
      <html>
        <head>
          <link rel='stylesheet' type='text/css' href='styles.css'>
        </head>
        <body>
          <table>
            <tr>
              <th>Header</th>
              <td>Data</td>
            </tr>
          </table>
         </body>
      </html>
    css
    /* In your CSS file (styles.css) */
    th { background-color: lightgreen; }
    tr { background-color: lightblue; }
    td { background-color: lightpink; }

    이와 같이 CSS를 사용하면 웹 페이지의 각 요소에 스타일을 적용할 수 있다. 이렇게 하는 것이 HTML 태그의 bgcolor 속성을 사용하는 것보다 권장되는 방법이다, bgcolor는 HTML 4.01에서는 지원되지만, HTML5에서는 더 이상 지원되지 않는다.



🚩 HTML/CSS 글 모음 (총 15 건)

HTML 문서내 목차만들고, 바로가기

Last Updated : 2023-09-29
#HTML #CSS #A태그 #a태그

유튜브 공유시 시작시간과 종료시간을 지정하는 방법

Last Updated : 2023-09-29
#HTML #YouTube

[HTML] 이미지 위에 버튼 링크 만들기

Last Updated : 2023-09-19
#HTML

[HTML] 이미지 위에 버튼 만들기

Last Updated : 2023-09-19
#HTML

[HTML] 다국어 웹사이트 구축 : 사용자 언어 자동 인식 및 설정 방법

Last Updated : 2023-09-05

[HTML] 구글 로그인 쉽게 구현하기

Last Updated : 2023-09-05