2016-08-30 3 views

답변

0

여기 다시는 jQuery를 몇 줄을 사용하는 유일한 솔루션 CSS의 아닌 솔루션입니다.

데모 용으로 여기에 jsFiddle이 있습니다.

HTML 코드 :

<table> 
    <thead> 
     <tr> 
      <th>Column 1</th> 
      <th>Column 2</th> 
      <th>Column 3</th> 
      <th>Column 4</th> 
      <th>Column 5</th> 
     </tr> 
    </thead> 
    <tbody> 
     <tr> 
      <td>Row 1</td> 
      <td>Row 1</td> 
      <td>Row 1</td> 
      <td>Row 1</td> 
      <td>Row 1</td> 
     </tr> 
     <tr> 
      <td>Row 2</td> 
      <td>Row 2</td> 
      <td>Row 2</td> 
      <td>Row 2</td> 
      <td>Row 2</td> 
     </tr> 
     <tr> 
      <td>Row 3</td> 
      <td>Row 3</td> 
      <td>Row 3</td> 
      <td>Row 3</td> 
      <td>Row 3</td> 
     </tr> 
     <tr> 
      <td>Row 4</td> 
      <td>Row 4</td> 
      <td>Row 4</td> 
      <td>Row 4</td> 
      <td>Row 4</td> 
     </tr> 
     <tr> 
      <td>Row 5</td> 
      <td>Row 5</td> 
      <td>Row 5</td> 
      <td>Row 5</td> 
      <td>Row 5</td> 
     </tr> 
     <tr> 
      <td>Row 6</td> 
      <td>Row 6</td> 
      <td>Row 6</td> 
      <td>Row 6</td> 
      <td>Row 6</td> 
     </tr> 
     <tr> 
      <td>Row 7</td> 
      <td>Row 7</td> 
      <td>Row 7</td> 
      <td>Row 7</td> 
      <td>Row 7</td> 
     </tr> 
     <tr> 
      <td>Row 8</td> 
      <td>Row 8</td> 
      <td>Row 8</td> 
      <td>Row 8</td> 
      <td>Row 8</td> 
     </tr> 
     <tr> 
      <td>Row 9</td> 
      <td>Row 9</td> 
      <td>Row 9</td> 
      <td>Row 9</td> 
      <td>Row 9</td> 
     </tr> 
     <tr> 
      <td>Row 10</td> 
      <td>Row 10</td> 
      <td>Row 10</td> 
      <td>Row 10</td> 
      <td>Row 10</td> 
     </tr> 
    </tbody> 
    <tfoot> 
     <tr> 
     <td> 
      FOOTER 
     </td> 
     <td> 
      FOOTER 
     </td> 
     <td> 
      FOOTER 
     </td> 
     <td> 
      FOOTER 
     </td> 
     <td> 
      FOOTER 
     </td> 
     </tr> 
    </tfoot> 
</table> 

CSS 코드

html { 
    font-family: verdana; 
    font-size: 10pt; 
    line-height: 25px; 
} 
table { 
    border-collapse: collapse; 
    width: 400px; 
    overflow-x: scroll; 
    display: block; 
} 
thead { 
    background-color: #EFEFEF; 
} 
thead, tbody { 
    display: block; 
} 
tbody { 
    overflow-y: scroll; 
    overflow-x: hidden; 
    height: 140px; 
} 
td, th { 
    min-width: 100px; 
    height: 25px; 
    border: dashed 1px lightblue; 
} 

JQuery와 코드 :이 도움이

$('table').on('scroll', function() { 
    $("table > *").width($("table").width() + $("table").scrollLeft()); 
}); 

희망!

+0

@jazid 감사합니다.하지만 1 열과 2 열을 고칠 생각이 있습니까? – edwinlab

+0

@edwinlab은 css 솔루션을 사용하여 make column을 수정했습니다. .static { 위치 : 절대; 너비 : 110px; 상단 : 자동; } .name { 왼쪽 : 0; } . 범주 { 왼쪽 : 110px; } 더 많은 도움이 필요하면 알려주세요! 감사합니다 –

+0

@ jazid jsfiddle을 업데이트 할 수 있습니까? 정말 고마워 – edwinlab

관련 문제