2016-09-26 22 views
1

我在表格上創建功能區,但面臨一些問題。 我不能在桌子上製作綵帶。一些它看起來很奇怪。使用CSS表格的功能區

.sash { 
 
    position: relative; 
 
    overflow: hidden; 
 
    width: 300px; 
 
} 
 
.sash:after { 
 
    content: "Sash"; 
 
    position: absolute; 
 
    width: 90px; 
 
    height: 30px; 
 
    background: red; 
 
    top: 0; 
 
    right: 0; 
 
    transform: rotate(49deg); 
 
}
<table style="border:1px solid black" class="sash"> 
 
    <tr> 
 
    <td>one line text</td> 
 
    <td>two line text</td> 
 
    <td>three line text</td> 
 
    <td>four line text</td> 
 
    <td width="100"></td> 
 
    </tr> 
 

 
    <tr> 
 
    <td>one line text</td> 
 
    <td>two line text</td> 
 
    <td>three line text</td> 
 
    <td>four line text</td> 
 
    <td width="100"></td> 
 
    </tr> 
 
</table>

+0

究竟是你想要的視覺效果是什麼? – Serlite

+0

與http://www.cssportal.com/blog/create-corner-ribbon/相同,但使用表格結構。 有沒有其他的方法可以避免像之前那樣的僞類? – Robin

回答

3

可能:

.sash { 
 
    position: relative; 
 
    overflow: hidden; 
 
    width: 300px; 
 
} 
 
.sash:after { 
 
    content: attr(data-ribbon); 
 
    position: absolute; 
 
    width: 90px; 
 
    height: 30px; 
 
    background: red; 
 
    top: 5px; 
 
    text-align: center; 
 
    line-height: 30px; 
 
    right: -27px; 
 
    transform: rotate(49deg); 
 
}
<table style="border:1px solid black" class="sash" data-ribbon="Sach"> 
 
    <tr> 
 
    <td>one line text</td> 
 
    <td>two line text</td> 
 
    <td>three line text</td> 
 
    <td>four line text</td> 
 
    <td width="100"></td> 
 
    </tr> 
 

 
    <tr> 
 
    <td>one line text</td> 
 
    <td>two line text</td> 
 
    <td>three line text</td> 
 
    <td>four line text</td> 
 
    <td width="100"></td> 
 
    </tr> 
 
</table>

對於每一行:

.sash tr td:last-child { 
 
    position: relative; 
 
    overflow: hidden; 
 
    width: 300px; 
 
} 
 
.sash tr td:last-child:after { 
 
    content: attr(data-ribbon); 
 
    position: absolute; 
 
    width: 90px; 
 
    height: 30px; 
 
    background: red; 
 
    top: 5px; 
 
    text-align: center; 
 
    line-height: 30px; 
 
    right: -12px; 
 
    transform: rotate(49deg); 
 
}
<table style="border:1px solid black" class="sash"> 
 
    <tr> 
 
    <td>one line text</td> 
 
    <td>two line text</td> 
 
    <td>three line text</td> 
 
    <td>four line text</td> 
 
    <td width="100" data-ribbon="One"></td> 
 
    </tr> 
 

 
    <tr> 
 
    <td>one line text</td> 
 
    <td>two line text</td> 
 
    <td>three line text</td> 
 
    <td>four line text</td> 
 
    <td width="100" data-ribbon="Two"></td> 
 
    </tr> 
 
</table>

+0

謝謝!有沒有其他的方法可以避免僞類?因爲我的腰帶價值將會是動態的。 – Robin

+0

@ user769456是的,使用_clever_僞...我將在一秒內更新答案。 – LGSon

+0

@ user769456使用'data-ribbon'屬性和CSS更新'attr()' – LGSon