Border style do not work with sticky position element

后端 未结 11 2284
攒了一身酷
攒了一身酷 2020-12-01 13:41

I don\'t know why my border style do not work with position: sticky; attribute. I would like to set border styles on my sticky table header. But I don\'t want t

11条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-01 14:21

    This is, I believe the simplest answer.

    The accepted answer don't provide a solution for a 1px border.

    Note: this is a work around, so don't gripe me.

    If you remove the border-top from the table header, the table has nothing to collapse, so no space is created to see through to the underlying cells. Replace the border-top with a border of the same style in a holding DIV.

    css:

    table thead tr:nth-child(1) th {
      position: sticky; 
      border-top:0;
    }
    
    .table_holder {
      border-top:1px solid black;
    }
    

    html:

    ...

提交回复
热议问题