2017-01-27 7 views
0

tbody에서 스크롤하는 테이블이 필요하지만 동시에 탄성이 있습니다 (창 또는 컨테이너의 100 %). https://jsfiddle.net/Ln8opp3v/) 탄성 :탄성 테이블 너비 고정 열 및 머리글

는 기본적으로, 나는 너무

누군가가 나에게이 JSFiddle의 테이블을 도울 수있는 고정 된 헤더와 마지막 열이있는 테이블이 필요하십니까?

.fixed_headers { 
 
    width: 750px; 
 
    table-layout: fixed; 
 
    border-collapse: collapse; 
 
} 
 
.fixed_headers th { 
 
    text-decoration: underline; 
 
} 
 
.fixed_headers th, 
 
.fixed_headers td { 
 
    padding: 5px; 
 
    text-align: left; 
 
} 
 
.fixed_headers td:nth-child(1), 
 
.fixed_headers th:nth-child(1) { 
 
    min-width: 200px; 
 
} 
 
.fixed_headers td:nth-child(2), 
 
.fixed_headers th:nth-child(2) { 
 
    min-width: 200px; 
 
} 
 
.fixed_headers td:nth-child(3), 
 
.fixed_headers th:nth-child(3) { 
 
    width: 350px; 
 
} 
 
.fixed_headers thead { 
 
    background-color: #333; 
 
    color: #FDFDFD; 
 
} 
 
.fixed_headers thead tr { 
 
    display: block; 
 
    position: relative; 
 
} 
 
.fixed_headers tbody { 
 
    display: block; 
 
    overflow: auto; 
 
    width: 100%; 
 
    height: 300px; 
 
} 
 
.fixed_headers tbody tr:nth-child(even) { 
 
    background-color: #DDD; 
 
} 
 
.old_ie_wrapper { 
 
    height: 300px; 
 
    width: 750px; 
 
    overflow-x: hidden; 
 
    overflow-y: auto; 
 
} 
 
.old_ie_wrapper tbody { 
 
    height: auto; 
 
}
<!-- IE < 10 does not like giving a tbody a height. The workaround here applies the scrolling to a wrapped <div>. --> 
 
<!--[if lte IE 9]> 
 
<div class="old_ie_wrapper"> 
 
<!--<![endif]--> 
 

 
<table class="fixed_headers"> 
 
    <thead> 
 
    <tr> 
 
     <th>Name</th> 
 
     <th>Color</th> 
 
     <th>Description</th> 
 
    </tr> 
 
    </thead> 
 
    <tbody> 
 
    <tr> 
 
     <td>Apple</td> 
 
     <td>Red</td> 
 
     <td>These are red.</td> 
 
    </tr> 
 
    <tr> 
 
     <td>Pear</td> 
 
     <td>Green</td> 
 
     <td>These are green.</td> 
 
    </tr> 
 
    <tr> 
 
     <td>Grape</td> 
 
     <td>Purple/Green</td> 
 
     <td>These are purple and green.</td> 
 
    </tr> 
 
    <tr> 
 
     <td>Orange</td> 
 
     <td>Orange</td> 
 
     <td>These are orange.</td> 
 
    </tr> 
 
    <tr> 
 
     <td>Banana</td> 
 
     <td>Yellow</td> 
 
     <td>These are yellow.</td> 
 
    </tr> 
 
    <tr> 
 
     <td>Kiwi</td> 
 
     <td>Green</td> 
 
     <td>These are green.</td> 
 
    </tr> 
 
    <tr> 
 
     <td>Plum</td> 
 
     <td>Purple</td> 
 
     <td>These are Purple</td> 
 
    </tr> 
 
    <tr> 
 
     <td>Watermelon</td> 
 
     <td>Red</td> 
 
     <td>These are red.</td> 
 
    </tr> 
 
    <tr> 
 
     <td>Tomato</td> 
 
     <td>Red</td> 
 
     <td>These are red.</td> 
 
    </tr> 
 
    <tr> 
 
     <td>Cherry</td> 
 
     <td>Red</td> 
 
     <td>These are red.</td> 
 
    </tr> 
 
    <tr> 
 
     <td>Cantelope</td> 
 
     <td>Orange</td> 
 
     <td>These are orange inside.</td> 
 
    </tr> 
 
    <tr> 
 
     <td>Honeydew</td> 
 
     <td>Green</td> 
 
     <td>These are green inside.</td> 
 
    </tr> 
 
    <tr> 
 
     <td>Papaya</td> 
 
     <td>Green</td> 
 
     <td>These are green.</td> 
 
    </tr> 
 
    <tr> 
 
     <td>Raspberry</td> 
 
     <td>Red</td> 
 
     <td>These are red.</td> 
 
    </tr> 
 
    <tr> 
 
     <td>Blueberry</td> 
 
     <td>Blue</td> 
 
     <td>These are blue.</td> 
 
    </tr> 
 
    <tr> 
 
     <td>Mango</td> 
 
     <td>Orange</td> 
 
     <td>These are orange.</td> 
 
    </tr> 
 
    <tr> 
 
     <td>Passion Fruit</td> 
 
     <td>Green</td> 
 
     <td>These are green.</td> 
 
    </tr> 
 
    </tbody> 
 
</table> 
 

 
<!--[if lte IE 9]> 
 
</div> 
 
<!--<![endif]-->

+0

당신이 '는 탄성 만드는'무엇을 의미합니까? –

+0

나는 창을 100 % 넣고 창 크기를 조정할 때 테이블 크기도 조정합니다. – Moutimedia

답변

0

나는 당신이하려는 그 목적을 이해하지 않습니다하지만 당신은 %와 그것을 달성뿐만 아니라 vw 측정 할 수 있습니다.

스크롤바가 필요하면 너비 또는 높이를 제한해야한다는 것을 잊지 마십시오. 유연한 콘텐츠는 스크롤바를 트리거하지 않습니다.

.fixed_headers { 
 
    width: 750px; 
 
    table-layout: fixed; 
 
    border-collapse: collapse; 
 
} 
 
.fixed_headers th { 
 
    text-decoration: underline; 
 
} 
 
.fixed_headers th, 
 
.fixed_headers td { 
 
    padding: 5px; 
 
    text-align: left; 
 
} 
 
.fixed_headers td:nth-child(1), 
 
.fixed_headers th:nth-child(1) { 
 
    min-width: 200px; 
 
} 
 
.fixed_headers td:nth-child(2), 
 
.fixed_headers th:nth-child(2) { 
 
    min-width: 200px; 
 
} 
 
.fixed_headers td:nth-child(3), 
 
.fixed_headers th:nth-child(3) { 
 
    width: 350px; 
 
} 
 
.fixed_headers thead { 
 
    background-color: #333; 
 
    color: #FDFDFD; 
 
} 
 
.fixed_headers thead tr { 
 
    display: block; 
 
    position: relative; 
 
    width: 100%; 
 
} 
 
.fixed_headers tbody { 
 
    display: block; 
 
    overflow: scroll; 
 
    width: 100vw; 
 
    height: 300px; 
 
} 
 
.fixed_headers tbody tr:nth-child(even) { 
 
    background-color: #DDD; 
 
} 
 
.old_ie_wrapper { 
 
    height: 300px; 
 
    width: 750px; 
 
    overflow-x: hidden; 
 
    overflow-y: auto; 
 
} 
 
.old_ie_wrapper tbody { 
 
    height: auto; 
 
}
<!-- IE < 10 does not like giving a tbody a height. The workaround here applies the scrolling to a wrapped <div>. --> 
 
<!--[if lte IE 9]> 
 
<div class="old_ie_wrapper"> 
 
<!--<![endif]--> 
 

 
<table class="fixed_headers"> 
 
    <thead> 
 
    <tr> 
 
     <th>Name</th> 
 
     <th>Color</th> 
 
     <th>Description</th> 
 
    </tr> 
 
    </thead> 
 
    <tbody> 
 
    <tr> 
 
     <td>Apple</td> 
 
     <td>Red</td> 
 
     <td>These are red.</td> 
 
    </tr> 
 
    <tr> 
 
     <td>Pear</td> 
 
     <td>Green</td> 
 
     <td>These are green.</td> 
 
    </tr> 
 
    <tr> 
 
     <td>Grape</td> 
 
     <td>Purple/Green</td> 
 
     <td>These are purple and green.</td> 
 
    </tr> 
 
    <tr> 
 
     <td>Orange</td> 
 
     <td>Orange</td> 
 
     <td>These are orange.</td> 
 
    </tr> 
 
    <tr> 
 
     <td>Banana</td> 
 
     <td>Yellow</td> 
 
     <td>These are yellow.</td> 
 
    </tr> 
 
    <tr> 
 
     <td>Kiwi</td> 
 
     <td>Green</td> 
 
     <td>These are green.</td> 
 
    </tr> 
 
    <tr> 
 
     <td>Plum</td> 
 
     <td>Purple</td> 
 
     <td>These are Purple</td> 
 
    </tr> 
 
    <tr> 
 
     <td>Watermelon</td> 
 
     <td>Red</td> 
 
     <td>These are red.</td> 
 
    </tr> 
 
    <tr> 
 
     <td>Tomato</td> 
 
     <td>Red</td> 
 
     <td>These are red.</td> 
 
    </tr> 
 
    <tr> 
 
     <td>Cherry</td> 
 
     <td>Red</td> 
 
     <td>These are red.</td> 
 
    </tr> 
 
    <tr> 
 
     <td>Cantelope</td> 
 
     <td>Orange</td> 
 
     <td>These are orange inside.</td> 
 
    </tr> 
 
    <tr> 
 
     <td>Honeydew</td> 
 
     <td>Green</td> 
 
     <td>These are green inside.</td> 
 
    </tr> 
 
    <tr> 
 
     <td>Papaya</td> 
 
     <td>Green</td> 
 
     <td>These are green.</td> 
 
    </tr> 
 
    <tr> 
 
     <td>Raspberry</td> 
 
     <td>Red</td> 
 
     <td>These are red.</td> 
 
    </tr> 
 
    <tr> 
 
     <td>Blueberry</td> 
 
     <td>Blue</td> 
 
     <td>These are blue.</td> 
 
    </tr> 
 
    <tr> 
 
     <td>Mango</td> 
 
     <td>Orange</td> 
 
     <td>These are orange.</td> 
 
    </tr> 
 
    <tr> 
 
     <td>Passion Fruit</td> 
 
     <td>Green</td> 
 
     <td>These are green.</td> 
 
    </tr> 
 
    </tbody> 
 
</table> 
 

 
<!--[if lte IE 9]> 
 
</div> 
 
<!--<![endif]-->

관련 문제