2013-07-23 65 views
0

表格元素的样式表不包括表格标题(<table>标记中的<caption>标记)。CSS:如何样式表背景,包括<caption>元素

有没有办法让表格具有包含标题的渐变背景?

+0

我不能找到一种方法来实现,但包裹台成一个div会,使格BG梯度只会解决您的问题 – insanebits

+0

这可能是有益的:HTTP:/ /dense13.com/blog/2008/08/23/styling-table-captions-with-css-fixing-the-width-problem/ –

回答

0

是的,有:http://jsfiddle.net/Pe5Lt/2/

位置标题absolute LY,relative LY表,然后把桌上的一些padding-top和中心标题与margin: Xpx auto;

HTML

<table> 
    <caption>I'm a CAPTION</caption> 
    <thead>   
     <tr> 
      <th>I'm a TH</th> 
     </tr> 
    </thead> 
    <tbody> 
     <tr> 
      <td>I'm a TD</td> 
     </tr> 
    </tbody> 
</table> 

CSS

table { 
    position: relative; 
    padding-top: 30px; 
    width: 200px; 
    border: 1px solid red; 
    background: rgb(30, 87, 153); 
    /* Old browsers */ 
    background: -moz-linear-gradient(top, rgba(30, 87, 153, 1) 0%, rgba(41, 137, 216, 1) 66%, rgba(32, 124, 202, 1) 100%, rgba(125, 185, 232, 1) 100%); 
    /* FF3.6+ */ 
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, rgba(30, 87, 153, 1)), color-stop(66%, rgba(41, 137, 216, 1)), color-stop(100%, rgba(32, 124, 202, 1)), color-stop(100%, rgba(125, 185, 232, 1))); 
    /* Chrome,Safari4+ */ 
    background: -webkit-linear-gradient(top, rgba(30, 87, 153, 1) 0%, rgba(41, 137, 216, 1) 66%, rgba(32, 124, 202, 1) 100%, rgba(125, 185, 232, 1) 100%); 
    /* Chrome10+,Safari5.1+ */ 
    background: -o-linear-gradient(top, rgba(30, 87, 153, 1) 0%, rgba(41, 137, 216, 1) 66%, rgba(32, 124, 202, 1) 100%, rgba(125, 185, 232, 1) 100%); 
    /* Opera 11.10+ */ 
    background: -ms-linear-gradient(top, rgba(30, 87, 153, 1) 0%, rgba(41, 137, 216, 1) 66%, rgba(32, 124, 202, 1) 100%, rgba(125, 185, 232, 1) 100%); 
    /* IE10+ */ 
    background: linear-gradient(to bottom, rgba(30, 87, 153, 1) 0%, rgba(41, 137, 216, 1) 66%, rgba(32, 124, 202, 1) 100%, rgba(125, 185, 232, 1) 100%); 
    /* W3C */ 
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#1e5799', endColorstr='#7db9e8', GradientType=0); 
    /* IE6-9 */ 
} 
table caption { 
    color: red; 
    position: absolute; 
    top: 0; 
    width: 100%; 
    margin: 10px auto; 
} 

CSS生成的渐变背景http://www.colorzilla.com/gradient-editor/

+0

我更新了我的问题,以阐明我的意思是“标题”。如果你可以修改你的小提琴来实现这一点,那将是非常棒的。 –

0

添加显示:块;要解决这个问题

<style> 
    table{ 
     background-image: -moz-linear-gradient(bottom, rgb(156,155,250) 43%, rgb(255,255,255) 88%); 
     display:block; 
    } 

<table> 
    <caption>Test</caption> 
    <tr> 
     <td>Col1</td> 
     <td>Col2</td> 
    </tr> 
</table>