If you're willing to set the width of the table, you can do it with css alone.
Revised css:
Code:
#ctable {
position: fixed;
top: 0;
left: 50%;
width: 110px;
margin-left: -56px; /* half the width + left padding and left border width, if either, expressed as a negative */
border: 1px solid black;
background-color: lightyellow;
z-index: 100000; /* only required if there are one or more other positioned elements on the page with z-index */
}
Of course this means you have to know what width to use. If the content of the table doesn't fit the width you set, it can look odd. Better to overestimate than underestimate. You can perhaps center the content in the cells to compensate for a too wide table. That would depend on if that looks OK or not with your content. Browsers may vary by a few pixels as to how much width they need. In those cases use the higher value for all. If you have no control over the content (if it can vary without your knowledge), this method will not work.
If you can do the css like that, you don't need the script. The table should still be the last thing before the closing </body> tag in the HTML code.
Bookmarks