Border style do not work with sticky position element

后端 未结 11 2286
攒了一身酷
攒了一身酷 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:17

    How about replacing border with outline? I dare to say that especially for table elements the outline acts almost the same as border. I know it is not out of the box model etc. but visually is identical here. Try this:

    table tr th,
    table tr td {
      border: 0; 
      outline: 2px solid;
    }
    

    Bear in mind, outline is always rendered around the whole element, there is nothing like outline-left, so it is not silver bullet. See outline on MDN for further details.

    UPDATE: Well I overlooked one detail, the outline is not properly aligned with tbody borders. You have to eiter swap border and outline for the whole table or use transform and nudge the thead, but perhaps it is not good way to go (it depends, of course).

提交回复
热议问题