1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | <!DOCTYPE html> <html lang="ko"> <head> <meta charset="utf-8"> <style> .fixed-table-container { width: 600px; height: 200px; border: 1px solid #000; position: relative; padding-top: 30px; /* header-bg height값 */ } .header-bg { background: skyblue; height: 30px; /* header-bg height값 */ position: absolute; top: 0; right: 0; left: 0; border-bottom: 1px solid #000; } .table-wrapper { overflow-x: hidden; overflow-y: auto; height: 100%; } table { width: 100%; border-collapse: collapse; } td { border-bottom: 1px solid #ccc; padding: 5px; } td + td { border-left: 1px solid #ccc; } th { padding: 0px; /* reset */ } .th-text { position: absolute; top: 0; width: inherit; line-height: 30px; /* header-bg height값 */ border-left: 1px solid #000; } th:first-child .th-text { border-left: none; } </style> </head> <body> <div class="fixed-table-container"> <div class="header-bg"></div> <div class="table-wrapper"> <table> <thead> <tr> <th width="20%"> <!-- %넓이 값을 지정을 위해 div를 포함시켰다. --> <div class="th-text">제목1</div> </th> <th width="30%"> <div class="th-text">제목2</div> </th> <th width="50%"> <div class="th-text">제목3</div> </th> </tr> </thead> <tbody> <tr> <td>1</td> <td>2</td> <td>3</td> </tr> <tr> <td>1</td> <td>2</td> <td>3</td> </tr> <tr> <td>1</td> <td>2</td> <td>3</td> </tr> <tr> <td>1</td> <td>2</td> <td>3</td> </tr> <tr> <td>1</td> <td>2</td> <td>3</td> </tr> <tr> <td>1</td> <td>2</td> <td>3</td> </tr> <tr> <td>1</td> <td>2</td> <td>3</td> </tr> <tr> <td>1</td> <td>2</td> <td>3</td> </tr> <tr> <td>1</td> <td>2</td> <td>3</td> </tr> <tr> <td>1</td> <td>2</td> <td>3</td> </tr> <tr> <td>1</td> <td>2</td> <td>3</td> </tr> <tr> <td>1</td> <td>2</td> <td>3</td> </tr> </tbody> </table> </div> </div> </body> </html> |
반응형
'CSS' 카테고리의 다른 글
[CSS] attr - 요소의 속성값(텍스트)을 :before, :after content에 넣기 (0) | 2016.11.07 |
---|---|
[CSS] animation (0) | 2016.08.31 |
[CSS] 자바스크립트 click이벤트 없이 CSS만으로 toggle 구현하기 (0) | 2016.07.12 |
[CSS] nth-child (n번째 부터 n번째 까지 css적용) (3) | 2016.07.05 |
[CSS] 2단 레이아웃 화면 100% 유지 (0) | 2016.07.04 |