简体   繁体   English

JS / CSS-保持td元素的宽度

[英]JS/CSS - Keeping the width of td element

I have some thing like 我有类似的东西

<table>   
   <thead>
     <tr class="class1"><td>Col 11</td><td>Col 12</td><td>Col 13</td></tr>   //Row 1
     <tr class="class2"><td>Col 21</td><td>Col 22</td><td>Col 23</td></tr>   //Row 2 
   </thead>   
   <tbody>
     <tr><td>D 11</td><td>D 12</td><td>D 13</td></tr>
     <tr><td>D 21</td><td>D 22</td><td>D 23</td></tr>
     .
     .
     <tr><td>D n1</td><td>D n2</td><td>D n3</td></tr>   
   </tbody>
 </table>

I want to make Row 1 and Row 2 stick to the top of the page when there are more rows in the tbody which i am doing with the following script, 当我使用以下脚本在tbody中有更多行时,我想使第1行和第2行停留在页面的顶部,

var c1 = $(".class1");
var c2 = $(".class2");
if(st > 315) {

    c1.css({
        position: "fixed",
        top: "110px"
    });
    c2.css({
        position: "fixed",
        top: "145px"
    });
} 
else {
    c1.css({
        position: "",
        top: "",

    });

    c2.css({
        position: "",
        top: "",

    });
}

When the two rows get to position:fixed the tboby contents get shrinked (as if thead and tbody are separate table elements) 当两行定位时:固定tboby的内容(如thead和tbody是单独的表元素)

I want the td to be fixed througout the process. 我希望在整个过程中都固定好td How to fix this issue ? 如何解决这个问题? :( :(

Thanks in advance. 提前致谢。

<td with="100px">...</td>

If you need position fix, use other element. 如果需要定位,请使用其他元素。 TD cant be position fixed. TD无法固定位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM