簡體   English   中英

表與漸變邊框和單元格漸變邊框

[英]Table with gradient borders and cell gradient borders

我想在邊框和div邊界上實現一個漸變的表格,因為它們是一個完整的項目,我的意思是單元格的邊框顏色應該是不同的。

表與漸變

這就是我到目前為止所得到的:

 table tr:first-child td { border-top: 0; } table tr:last-child td { border-bottom: 0; } table tr td:last-child { border-right: 0; border-left: 0; } table tr td:first-child { border-left: 0; } td { border-right: 2px solid #bebebe; border-bottom: 2px solid #bebebe; } td { border-collapse: collapse; } table { /*border-collapse: collapse;*/ border-style: solid; border-width: 20px 20px; border-image-source: linear-gradient(to bottom, #eee 0%, #bebebe 100%); border-image-slice: 20; border-image-repeat: stretch; box-shadow: 0px 10px 10px black; } body { background-color: #eee; } 
 <table class="tablagradiente" align="center" width="41%"> <tr> <td> <p>Sesiones Ordinarias</p> </td> <td> <p>Sesiones Extraordinarias</p> </td> </tr> <tr> <td> <p>&nbsp;</p> </td> <td> <p>Primera Sesión Extraordinaria 2015</p> </td> </tr> </table> 

通過設置以下內容,您實際上可以在沒有border-image屬性的情況下實現您想要的效果:

table {
  background-image: linear-gradient(to bottom, red 0%, blue 100%); /* the gradient */
  background-origin: border-box; /* set background to start from border-box */
  border-spacing: 5px; /* space between each cell */
  border: 5px solid transparent; /* optional */
}

瀏覽器支持:


說明

實質上我們在這里做的是以下內容:

  • 添加linear-gradient作為表格的background
  • 設置背景的原點,使其從表格的border-box開始。 (有關background-origin更多詳情,請參閱我的答案 )。
  • 分隔表格單元格和行之間的邊界( 默認設置),以便通過其間的空間可以看到tablebackground
  • 為表本身添加額外的透明border 這是可選的,僅需要,因為圖像中的表格邊框看起來比單元格之間的邊框更粗。

 table { background-image: linear-gradient(to bottom, red 0%, blue 100%); /* the gradient */ background-origin: border-box; /* set background to start from border-box */ border-spacing: 5px; /* space between each cell */ border: 5px solid transparent; /* optional */ } body { background-color: #eee; } /* Just for demo */ table { width: 500px; } td { background: white; /* if not set cell would also be transparent and show the gradient */ } 
 <!-- prefix free lib for older browsers --> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script> <table class="tablagradiente" align="center" width="41%"> <tr> <td><p>Sesiones Ordinarias</p></td> <td><p>Sesiones Extraordinarias</p></td> </tr> <tr> <td><p>&nbsp;</p></td> <td><p>Primera Sesión Extraordinaria 2015</p></td> </tr> <tr> <td><p>&nbsp;</p></td> <td><p>Primera Sesión Extraordinaria 2015</p></td> </tr> <tr> <td><p>&nbsp;</p></td> <td><p>Primera Sesión Extraordinaria 2015</p></td> </tr> </table> 

注意:我在答案中使用了紅色到藍色漸變,使效果更明顯。

在此輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM