这里显示了我遇到的问题。基本上当我在thead上放一个渐变时,Chrome会重复这个渐变为永远的细胞...实际的期望结果是firefox产生的 - 整个thead的一个坚实的渐变。
有关如何解决此问题的任何想法?
这是我的css:
thead.header {
font-weight: bold;
border-bottom: 1px solid #9C9C9C;
background-repeat: no-repeat;
background: #C6C6C6;
background: -moz-linear-gradient(top, #DEDEDE 0%, #BDBDBD 80%, #BBB 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#DEDEDE), color-stop(80%,#BDBDBD), color-stop(100%,#BBB));
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#DEDEDE', endColorstr='#BBB',GradientType=0 );
}
如果它有帮助,这是html:
<table style="width:100%" cellpadding="0" cellspacing="0">
<thead class="header">
<tr>
<th width="200px">Actor</th>
<th rowspan="3">Character</th>
</tr>
<tr>
<th>Gender</th>
</tr>
<tr>
<th>Age</th>
</tr>
</thead>
<tbody class="odd">
<tr>
<td width="200px">Test</td>
<td rowspan="3">Test</table>
</td>
</tr>
<tr>
<td>Male</td>
</tr>
<tr>
<td>25</td>
</tr>
</tbody>
</table>
答案 0 :(得分:5)
在thead上设置background-attachment:fixed;
,它会正常工作
答案 1 :(得分:4)
答案 2 :(得分:2)
我认为这是因为background
样式无法应用于thead
元素。
答案 3 :(得分:2)
将渐变应用于th
元素而不是thead
并使用rowspan
属性选择器似乎可行。如果两个标题行的高度是灵活的,因为您需要知道示例中的中间范围颜色#7E7E7E
,这将无法正常工作。查看exmaple http://jsfiddle.net/wSWF9/2/
table {
border: 1px solid #ccc;
border-collapse: collapse;
}
table thead th[rowspan="2"] {
background-image: linear-gradient(to bottom, #ccc, #333);
background-image: -webkit-linear-gradient(top, #ccc, #333);
background-repeat: repeat-x;
}
table thead tr th {
background-image: linear-gradient(to bottom, #ccc, #7E7E7E);
background-repeat: repeat-x;
}
table thead tr + tr th {
background-image: linear-gradient(to bottom, #7E7E7E, #333);
background-repeat: repeat-x;
}
答案 4 :(得分:2)
答案 5 :(得分:1)
嗯,绕过问题的方法是不使用单独的单元格,而是使用<br />
代替。
我意识到这不是一个很好的修复。
您的代码包含修复:http://jsbin.com/ozuhi5/2
新<thead>
:
<thead class="header">
<tr>
<th width="200">
Actor<br />
Gender<br />
Age
</th>
<th>Character</th>
</tr>
</thead>
答案 6 :(得分:0)
Google Chrome上的一个错误在this Google page about issues on Chrome上详细了解了它。
我在尝试设置tbody元素时遇到了同样的问题,这是我用来修复代码而不破坏其他浏览器支持的解决方案:
table>tbody {
background-image: -moz-linear-gradient(270deg, black, white); /* keep the right code for other browsers */
background-image: -ms-linear-gradient(270deg, black, white);
background-image: -o-linear-gradient(270deg, black, white);
background-image: linear-gradient(to bottom, black, white);
background-color: transparent; /* needed for chrome*/
background-image:-webkit-linear-gradient(0deg, rgba(0,0,0,0),rgba(0,0,0,0)); /*del the linear-gradient on google chrome */
}
table { /*fix tbody issues on google chrome engine*/
background-image: -webkit-linear-gradient(270deg, rgba(0,0,0,0) 39px, black 0px,white ); /* 359px is the calculated height of the thead elemx */
border-spacing: 0; /*delete border spacing */
}
请参阅此Fiddle
上的演示