[英]Table with gradient borders and cell gradient borders
I'd like to achieve a table with gradient on the border and div borders acting as is they were a whole item, by that I mean that the border color of the cells should be diferent. 我想在边框和div边界上实现一个渐变的表格,因为它们是一个完整的项目,我的意思是单元格的边框颜色应该是不同的。
That's what I've got so far: 这就是我到目前为止所得到的:
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> </p> </td> <td> <p>Primera Sesión Extraordinaria 2015</p> </td> </tr> </table>
You can actually achieve what you want without border-image
property just by setting the following: 通过设置以下内容,您实际上可以在没有
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 */
}
Browser Support: 浏览器支持:
In essence what we are doing here is the following: 实质上我们在这里做的是以下内容:
linear-gradient
as the background
of the table. linear-gradient
作为表格的background
。 border-box
of the table. border-box
开始。 (For more details on background-origin
, please refer my answer here ). background-origin
更多详情,请参阅我的答案 )。 background
of the table
is visible through the space in between. table
的background
。 border
to your table itself. border
。 This is optional and is only required because the table border in your image seems thicker than the border between the cells. 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> </p></td> <td><p>Primera Sesión Extraordinaria 2015</p></td> </tr> <tr> <td><p> </p></td> <td><p>Primera Sesión Extraordinaria 2015</p></td> </tr> <tr> <td><p> </p></td> <td><p>Primera Sesión Extraordinaria 2015</p></td> </tr> </table>
Note: I have used a red to blue gradient in the answer to make the effect more apparent to the eye. 注意:我在答案中使用了红色到蓝色渐变,使效果更明显。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.