메뉴 건너뛰기

프로그램언어

조회 수 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. No Image 06Dec
    by
    2016/12/06 Views 43313 

    특수문자, 특수문자표, 특수문자 하트, 예쁜 특수문자

  2. No Image 14Apr
    by
    2017/04/14 Views 3462 

    viewport 정리

  3. viewport meta 태그를 이용해 모바일 브라우저상에서 레이아웃 조종하는 법

  4. No Image 24Aug
    by
    2018/08/24 Views 1677 

    form안의 button submit 동작 막기

  5. No Image 27Oct
    by
    2018/10/27 Views 1127 

    FCKeditor 2.6.x 버전 IE9에서의 Dialog 버그 수정

  6. No Image 16Jan
    by
    2019/01/16 Views 2057 

    테이블 대신 필드셋(fieldset) 이용

  7. input 자동완성 끄기 HTML

  8. div iframe 퍼센트 높이조절 문제 해결(div, iframe height 100%)

  9. No Image 29Apr
    by
    2019/04/29 Views 733 

    네이버 웹마스터도구 메타태그

  10. 크롬 알림처럼 띄워보기

  11. 09Mar
    by 조쉬
    2021/03/09 Views 679 

    HTML, CSS - 헤더컬럼 고정형 table 구성하기

  12. HTML - Table td안에 특수문자(")가 존재할 경우 넓이 초과 현상

  13. CSS - p태그 등 너무 긴 문자열이 존재할 때, 넓이에 따른 자동 줄바꿈

  14. No Image 09Mar
    by
    2021/03/09 Views 102 

    HTML - Form 태그, Input 태그 자동완성 해제하기

  15. No Image 25Mar
    by
    2021/03/25 Views 128 

    javascript로 alt 또는 title 달때 내용에 포함된 따옴표 치환하기

  16. No Image 25Mar
    by
    2021/03/25 Views 84 

    인라인 자동완성 기능 막기

  17. No Image 26Mar
    by
    2021/03/26 Views 304 

    input태그 tab 순서 설정 : tabindex

  18. No Image 26Mar
    by
    2021/03/26 Views 161 

    map태그에서 window.open() 쓰기

  19. No Image 26Mar
    by
    2021/03/26 Views 227 

    MSword : 인쇄 미리보기-한페이지씩 보이기

  20. No Image 12Jan
    by
    2023/01/12 Views 180 

    Input 태그 한글, 영문모드 전환

Board Pagination Prev 1 2 Next
/ 2

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved