您對此有何想法?
<style>
.table {
width: 100%;
display:table;
border-collapse: collapse;
}
.tr {
height: 60px;
display:table-row;
border: 1px solid Black;
}
.td, .th{
height: 60px;
border: 1px solid Black;
display:table-cell;
background: -webkit-linear-gradient(top, #ccc 0%, #888 100%);
}
</style>
<div class="table">
<div class="tr">
<div class="th"></div>
</div>
<div class="tr">
<div class="td"></div>
</div>
<div class="tr">
<div class="td"></div>
</div>
</div>
最好使用DIV而不是表格。你可以用小的改變做同樣的事情。 如果您使用PDF或通過模板等電子郵件發送,那麼最好將CSS內聯添加到HTML。
UPDATE:
你可以這樣做:
<style>
table {
width: 100%;
border-collapse: collapse;
}
th {
height: 60px;
}
td{height: 100px;}
td, th {
background: -webkit-linear-gradient(top, #ccc 0%, #888 100%);
border: 1px solid Black;
}
</style>
<table>
<tr>
<th></th>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
</table>
或jQuery來使用嵌套的div替換表:
<style>
.table {
width: 100%;
display:table;
border-collapse: collapse;
}
.table .tr{
display:table-row;
}
.table .th{
height: 60px;
font-weight:bold;
}
.table .td{height: 100px;}
.table .th,
.table .td {
border: 1px solid Black;
display:table-cell;
background: -webkit-linear-gradient(top, #ccc 0%, #888 100%);
}
</style>
<table>
<tr>
<th>a</th>
</tr>
<tr>
<td>b</td>
</tr>
<tr>
<td>c</td>
</tr>
</table>
<script>
$(document).ready(function(){
$("table").each(function(a,table){
var i=a;
$(table).after('<div class="table" id="table-'+i+'"></div>');
var currentTH = $(this).parent().find('th');
$(currentTH).each(function(){
var content=$(this).html();
$('#table-'+i).append(' <div class="tr"><div class="th">'+content+'</div></div>');
});
var currentTD = $(this).parent().find('td');
$(currentTD).each(function(){
var content=$(this).html();
$('#table-'+i).append(' <div class="tr"><div class="td">'+content+'</div></div>');
});
$(this).remove();
});
});
</script>
我不認爲這將工作不幸。但是,您仍然可以通過使用圖像作爲背景來實現幾乎僅限CSS的解決方案。這對你有用嗎? – Nenotlep 2014-12-23 09:01:56
帶有圖像解決方案的CSS對我來說已經足夠好了,但是也可以用這種方法觀察到類似的突變渲染。 – stovroz 2014-12-23 16:32:13
以下兩點對我來說都是一樣的:'background:-webkit-gradient(線性,左上,右下,色阻(0%,rgba(25,25,175,1)),color-stop( (100%,rgba(93,168,226,1)));' 和'background:-webkit-gradient(linear,left top (rgba(25,25,175,1))到(rgba(93,168,226,1)));' – rainabba 2016-02-04 00:18:47