Border style do not work with sticky position element

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

    Now I can set the border styles with psuedo classes as user @soulshined suggested. Belows are css changes to work and here is JSFiddle Link. Already tested on chrome and firefox.

    #wrapper {
      width: 400px;
      height: 200px;
      overflow: auto;
      padding: 1px;
    }
    
    table {
      width: 100%;
      text-align: center;
      border-collapse: collapse;
    }
    table tr th {
      border: 1px solid green;
    }
    table tr th:first-child {
      border-left: 1px solid green;
    }
    table tr td {
      border: 1px solid green;
    }
    
    table thead th {
      position: -webkit-sticky;
      position: sticky;
      top: 0;
      background-color: #edecec;
    }
    
    th::before {
      content: '';
      position: absolute;
      left: 0;
      width: 100%;
      height: 100%;
      border-right: 1px solid green;
      display: block;
      top : 1px;
    }
    
    th::after {
      content: '';
      position: absolute;
      left: 0;
      width: 100%;
      height: 100%;
      border-bottom: 1px solid green;
      border-top: 1px solid green;
      display: block;
      top : -1px;
    }
    

提交回复
热议问题