메뉴 건너뛰기

프로그램언어

조회 수 679 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부

Table 태그를 구성하다보면 데이터가 길어질 경우를 대비해서 스크롤을 내리더라도 헤더컬럼부분을 고정으로 주고

아래 데이터부분만 스크롤이 되도록 처리하는 경우가 있습니다.

 

헤더가 고정된 테이블

 

 

"<table>" 태그를 "<thead>"와 "<tbody>" 형태로 구성하시고 "<thead> <th>"에는 position: sticky를 처리하면 고정형 테이블을 구성할 수 있습니다.

 

다만, sticky의 경우 IE에서 지원이 안되기때문에 static으로 동작하여 일반적인 테이블처럼 동작하게 됩니다.

아래는 sticky를 사용하여 고정헤더 테이블 샘플 예제 소스입니다.

 

헤더 고정하기

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Table</title>
    <style>
        *{margin:0; padding:0;}
        html, body, .wrapper{width:100%; height: 100vh;}
        .wrapper .tableBox{position: relative; top: 50px; left: 50px; width: 700px; height: 100px; overflow-y: scroll; border-top: 2px solid dodgerblue;}
        .tableData{width: 100%; border-collapse: collapse; text-align: center;}
        .tableData thead tr th{position: sticky; top: 0; background: #ebeaea;}
        .tableData thead tr th,
        .tableData tbody tr td{padding: 15px 0; box-sizing: border-box; border-bottom: 1px solid #dedede; border-right: 1px solid #ddd; word-break: break-all;}
    </style>
</head>
<body>
    <div class="wrapper">
        <div class="tableBox">
            <table class="tableData">
                <colgroup>
                    <col width="8%">
                    <col width="15%">
                    <col width="25%">
                    <col width="16%">
                    <col width="12%">
                    <col width="12%">
                    <col width="12%">
                </colgroup>
                <thead>
                    <tr>
                        <th class="stiky">순번</th>
                        <th class="stiky">구분</th>
                        <th class="stiky">제목</th>
                        <th class="stiky">글쓴이</th>
                        <th class="stiky">날짜</th>
                        <th class="stiky">첨부파일</th>
                        <th class="stiky">비고</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>1</td>
                        <td>공지사항</td>
                        <td>제목입니다.</td>
                        <td>홍길동</td>
                        <td>2020-11-26</td>
                        <td>-</td>
                        <td>-</td>
                    </tr>
                    <tr>
                        <td>2</td>
                        <td>공지사항</td>
                        <td>제목 "1","2","3","4","5","6","7","8","9","10","11"</td>
                        <td>홍길동</td>
                        <td>2020-11-26</td>
                        <td>-</td>
                        <td>-</td>
                    </tr>
                    <tr>
                        <td>3</td>
                        <td>게시판</td>
                        <td>123456789123456789123456789</td>
                        <td>홍길동</td>
                        <td>2020-11-26</td>
                        <td>-</td>
                        <td>-</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</body>
</html>

thead 태그의 th들에게 position:sticky를 처리하여 고정시킨 예제입니다.

주의점으로 thead나 thead tr에 sticky를 줘도 동작하지 않기에 꼭 thead영역의 th들에게 sticky처리를 하셔야 합니다.

 


  1. HTML 특수문자 / 띄어쓰기,공백, 따옴표

    Date2023.01.27 Views442
    Read More
  2. input 속성 readonly, disabled 차이점

    Date2023.01.27 Views64
    Read More
  3. Input 태그 한글, 영문모드 전환

    Date2023.01.12 Views180
    Read More
  4. MSword : 인쇄 미리보기-한페이지씩 보이기

    Date2021.03.26 Views227
    Read More
  5. map태그에서 window.open() 쓰기

    Date2021.03.26 Views161
    Read More
  6. input태그 tab 순서 설정 : tabindex

    Date2021.03.26 Views304
    Read More
  7. 인라인 자동완성 기능 막기

    Date2021.03.25 Views84
    Read More
  8. javascript로 alt 또는 title 달때 내용에 포함된 따옴표 치환하기

    Date2021.03.25 Views128
    Read More
  9. HTML - Form 태그, Input 태그 자동완성 해제하기

    Date2021.03.09 Views102
    Read More
  10. CSS - p태그 등 너무 긴 문자열이 존재할 때, 넓이에 따른 자동 줄바꿈

    Date2021.03.09 Views543
    Read More
  11. HTML - Table td안에 특수문자(")가 존재할 경우 넓이 초과 현상

    Date2021.03.09 Views205
    Read More
  12. HTML, CSS - 헤더컬럼 고정형 table 구성하기

    Date2021.03.09 Views679
    Read More
  13. 크롬 알림처럼 띄워보기

    Date2019.04.29 Views803
    Read More
  14. 네이버 웹마스터도구 메타태그

    Date2019.04.29 Views733
    Read More
  15. div iframe 퍼센트 높이조절 문제 해결(div, iframe height 100%)

    Date2019.03.05 Views942
    Read More
  16. input 자동완성 끄기 HTML

    Date2019.02.19 Views1050
    Read More
  17. 테이블 대신 필드셋(fieldset) 이용

    Date2019.01.16 Views2057
    Read More
  18. FCKeditor 2.6.x 버전 IE9에서의 Dialog 버그 수정

    Date2018.10.27 Views1127
    Read More
  19. form안의 button submit 동작 막기

    Date2018.08.24 Views1677
    Read More
  20. viewport meta 태그를 이용해 모바일 브라우저상에서 레이아웃 조종하는 법

    Date2017.04.14 Views6815
    Read More
Board Pagination Prev 1 2 Next
/ 2

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved