javascript - How to set html table height and column widths? -


i attempting control height of table body scrollbar appears when more data fits in view displayed, thead must stay visible. @ same time i'm trying control width of table columns.

the table height can controlled setting 'display: block' in table body css. table body limited container height or height table body set to. messes column widths though.

the column widths can assured setting desired. long tbody isn't set 'display: block' columns display tbody out of control , ignores height may have set.

i'm trying make possible result chapter 508 compliant screen reader technology disabilities. @ point, i'm planning convert jquery.datatables puts view port on top of table can keep 508 compliance , functionality need. seems way on top i'm wanting accomplish can't find simple way native table , basic css.

test code follows:

<div id="div1"> <table>     <colgroup>         <col id='col-1'>         <col id='col-2'>     </colgroup>     <thead>         <tr>             <th>month</th>             <th>savings</th>         </tr>     </thead>     <tbody>         <tr>             <td>january</td>             <td>$100</td>         </tr>         <tr>             <td>february long month seems go on forever!</td>             <td>$80</td>         </tr>         <tr>             <td>march</td>             <td>$180</td>         </tr>         <tr>             <td>april</td>             <td>$86</td>         </tr>         <tr>             <td>may</td>             <td>$98</td>         </tr>         <tr>             <td>june</td>             <td>$29</td>         </tr>         <tr>             <td>july</td>             <td>$44</td>         </tr>         <tr>             <td>august</td>             <td>$244</td>         </tr>     </tbody> </table> 

#div1 { height: 100px; width: 400px; padding: .5px; border: 1px solid red; } colgroup { width: 100%; } #col-1 { width:70%; } #col-2 { width:30%; } table { width: 100%; table-layout: auto; } thead { background-color: #b2dfff; } tbody { height: 72px; overflow-y: scroll; background-color: #f0f0f0; /* display:block;   set column width correctly messes tbody height */ display:block;  /* allow height set messes columns width */ } 

does have ideas?

add overflow: auto container div's css.

link jsfiddle: http://jsfiddle.net/bmarple/nk378/10/


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -