2016-08-02 191 views
0

以外的內容我試圖給一個自定義div表的所有行顯示數字以外的內容如何顯示在下圖所示的圖像上。 但我不知道如何使用CSS,如果有人可以幫助我的好主意。 我曾嘗試使用:之前和添加內容,但我不知道爲什麼不工作:|顯示內容

enter image description here

This is a small fiddle with my div table .

+0

讓出去了與數字的單元格。僅在​​附近放置邊界。 –

回答

1

你可以使用CSS計數器。

顯示他們在該行僞元素:

.table { 
 
    display:table; 
 
    border: 2px solid #444; 
 
    border-collapse: collapse; 
 
    margin-left: 50px; 
 
    margin-top: 50px; 
 
} 
 
.row { 
 
    display:table-row; 
 
    position: relative; 
 
} 
 
.cell { 
 
    display:table-cell; 
 
    padding:2px; 
 
    border: 1px solid #ccc; 
 
} 
 
.header { 
 
    font-weight:bold; 
 
    text-align:center; 
 
    position: relative; 
 
} 
 

 
.row:nth-child(n+2) { 
 
    counter-increment: rowno;     
 
} 
 
.row:nth-child(n+2)::before { 
 
    content: counter(rowno); 
 
    position: absolute; 
 
    left: 30px; 
 
} 
 
.row:first-child::before { 
 
    content: ""; 
 
    position: absolute; 
 
    left: 30px; 
 
} 
 

 
.header { 
 
counter-increment: colno;     
 
} 
 
.header::before { 
 
    content: counter(colno); 
 
    position: absolute; 
 
    top: -30px; 
 
}
<div class="table"> 
 
    <div class="row"> 
 
    <div class="cell header">Team</div> 
 
    <div class="cell header">Wins</div> 
 
    <div class="cell header">Losses</div> 
 
    <div class="cell header">Pct</div> 
 
    </div> 
 
    <div class="row"> 
 
    <div class="cell">Bulls</div> 
 
    <div class="cell">29</div> 
 
    <div class="cell">18</div> 
 
    <div class="cell">.617</div> 
 
    </div> 
 
    <div class="row"> 
 
    <div class="cell">Pacers</div> 
 
    <div class="cell">28</div> 
 
    <div class="cell">19</div> 
 
    <div class="cell">.596</div> 
 
    </div> 
 
    <div class="row"> 
 
    <div class="cell">Bucks</div> 
 
    <div class="cell">25</div> 
 
    <div class="cell">21</div> 
 
    <div class="cell">.617</div> 
 
    </div> 
 
</div>

+0

嘿我喜歡你的想法,但不幸的是,頂級櫃檯不工作:(只有左側櫃檯正在工作 – BurebistaRuler

+0

在你的問題你陳述**我試圖編號的所有行... ** – vals

+0

沒關係。 ..完成:-) – vals

2

下面是一個例子:

.table { 
 
    display:table; 
 
    border: 0px solid #444; 
 
    border-collapse: collapse; 
 
} 
 
.row { 
 
    display:table-row; 
 
} 
 
.cell { 
 
    display:table-cell; 
 
    padding:2px; 
 
    border: 1px solid #ccc; 
 
} 
 
.header { 
 
    font-weight:bold; 
 
    text-align:center; 
 
}
<div class="table"> 
 
    <div class="row" style="border-width:0"> 
 
    <div class="" style="border-width:0"></div> 
 
    <div class="cell" style="border-width:0">1</div> 
 
    <div class="cell" style="border-width:0">2</div> 
 
    <div class="cell" style="border-width:0">3</div> 
 
    <div class="cell" style="border-width:0">4</div> 
 
    </div> 
 
    <div class="row"> 
 
    <div class=" header">1</div> 
 
    <div class="cell header">Team</div> 
 
    <div class="cell header">Wins</div> 
 
    <div class="cell header">Losses</div> 
 
    <div class="cell header">Pct</div> 
 
    </div> 
 
    <div class="row"> 
 
    <div class="">2</div> 
 
    <div class="cell">Bulls</div> 
 
    <div class="cell">29</div> 
 
    <div class="cell">18</div> 
 
    <div class="cell">.617</div> 
 
    </div> 
 
    <div class="row"> 
 
    <div class="">3</div> 
 
    <div class="cell">Pacers</div> 
 
    <div class="cell">28</div> 
 
    <div class="cell">19</div> 
 
    <div class="cell">.596</div> 
 
    </div> 
 
    <div class="row"> 
 
    <div class="">4</div> 
 
    <div class="cell">Bucks</div> 
 
    <div class="cell">25</div> 
 
    <div class="cell">21</div> 
 
    <div class="cell">.617</div> 
 
    </div> 
 
</div>

http://fiddle.jshell.net/RFWT5/23/