html - How can I simply freeze the first row of my table using pure Javascript, no plugins? -
i need table work in latest version of google chrome (so no need worry cross-browser solutions, older versions of ie, etc.)
i looking solution freeze first row , not having success. if exclude word relative
in css position: fixed relative;
header rows stack on top of each other. not sure how header stay @ top of screen when scroll.
code table
<html> <head> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $( "#status_report .measure[data-bg='1']").css('background', 'red'); $( "#status_report .measure[data-bg='2']").css('background', 'grey'); $( "#status_report .measure[data-bg='3']").css('background', 'yellow'); $( "#status_report .measure[data-bg='4']").css('background', 'green'); }); </script> <style type="text/css"> th{ position: fixed relative; background:#111; color:#fff; padding: 2px; } td { background:#ddd; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 2px; } </style> </head> <body> <table id="status_report"> <tr> <th>field1</th> <th>field2</th> <th>field3</th> </tr> <tr> <?php foreach( $data $row ) : ?> <tr> <td><?php echo $row['field1']; ?></td> <td class = "measure" data-bg="<?php echo $row['field2']; ?>"><?php echo $row['field2']; ?></td> <td class = "measure" data-bg="<?php echo $row['field3']; ?>"><?php echo $row['field3']; ?></td> </tr> <? endforeach; $dbh = null; ?> </table> </body> </html>
position: fixed relative
invalid css. when set fixed
, position "resets", in, object not stay "where it's suppose be" , became relative document, need set it's position using top
, left
etc.
that's why stack.
Comments
Post a Comment