0

表格元素的样式表不包括表格标题(<caption>标签内的<table>标签)。

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

4

2 回答 2

1

添加显示:块;应该解决它

<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>
于 2013-07-23T11:53:48.653 回答
0

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

将标题absolutely, relatively 放在桌子上,然后给桌子一些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;
}

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

于 2013-07-23T11:46:55.767 回答