2016-01-20 24 views
0

我會開始說,我不擅長CSS,所以這可能很簡單。我有一個表頭,我想在滾動時修復它。當我添加位置:固定到CSS,滾動時它是固定的,但失去了它的間距格式。CSS標題位置固定刪除間距

之前 '的位置是:固定': enter image description here

這是後 '的位置是:固定': enter image description here

.consumer-service-table-header-style { 
 
    background-color: #d3d3d3; 
 
    width: 100%; 
 
    position: fixed; 
 
}
<thead class="consumer-service-table-header-style"> 
 
    <tr> 
 
     <td align="left">    
 
      <label style="font-weight: bold;">Pull Date</label> 
 
     </td> 
 
     <td align="left"> 
 
      <label style="font-weight: bold;">Rate</label> 
 
     </td> 
 
     <td align="left"> 
 
      <label style="font-weight: bold;">Service SubCat</label> 
 
     </td> 
 

 
     <td align="left"> 
 
     <label style="font-weight: bold;">ClientServiceIdMin</label> 
 
     </td> 
 
     <td align="left"> 
 
     <label style="font-weight: bold;">ClientServiceIdMax</label> 
 
     </td> 
 
     <td align="left"> 
 
     <label style="font-weight: bold;">Provider Name</label></td> 
 
     <td align="left"> 
 
     <label style="font-weight: bold;">RatePullId</label> 
 
     </td> 
 
     <td align="left"> 
 
     <label style="font-weight: bold;">DDS #</label> 
 
     </td> 
 
    </tr> 
 
</thead>

+0

更改位置:固定;定位:固定*重要; – Kami

+0

我做到了,結果相同: -/ – Matt

+0

您的桌子設置爲100%寬度嗎?沒有它,它就無法工作。 – Kami

回答

0

加入display: table;你的課應該保持它的所有很好地隔開!

+0

更好,但仍然關閉。它正在接近! – Matt

+0

你也可以嘗試在'td'上添加'display:table-cell' –

+0

如果我這樣做了,並且不向'css'添加一個'width'屬性,它會將它全部縮小,如果我添加一個「寬度:100%「的頭部CSS,頭部出去我的div。 – Matt

0

據我瞭解,您的桌子周圍有指定寬度的div。當您將position: fixed;更改爲position fixed *important;時,將display:table;更改爲.consumer-service-table-header-style類,則應該得到期望的結果。