html - 使用 html/css 在表格的 td 上拉伸(stretch)背景图像

标签 html css image html-table stretch

我有一张 table ,希望某个背景在 TD 的宽度上拉伸(stretch),无论宽度是多少。

我的相关 td 的 CSS 目前是这样的:

.tools .theader
{
margin:1px;background-color:#ffffcc;
background:url(../images/td_bg.png) no-repeat center center;
}

HTML 是这样的:

<table class'tools'>
<tr>
<td class='theader' colspan=2>
Background
</td>
...

这是我得到的结果的图像: enter image description here

因此您可以看到蓝色斜面背景恰好位于每个 td 的中心。我希望它拉伸(stretch)到 td 的边缘,这样整个 td 看起来都是斜面的。如何做到这一点?

最佳答案

你可以改用css渐变

HTML

<table class'tools'>
<tr>
<td class='theader' colspan="2">
    <span>Background</span>
</td>
    </tr>
    </table>

CSS

.theader > span{
    color:white;
    padding:6px 10px;
    background: #fffcfc; /* Old browsers */
background: -moz-linear-gradient(top,  #fffcfc 0%, #2989d8 12%, #2989d8 51%, #207cca 96%, #ffffff 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#fffcfc), color-stop(12%,#2989d8), color-stop(51%,#2989d8), color-stop(96%,#207cca), color-stop(100%,#ffffff)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top,  #fffcfc 0%,#2989d8 12%,#2989d8 51%,#207cca 96%,#ffffff 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top,  #fffcfc 0%,#2989d8 12%,#2989d8 51%,#207cca 96%,#ffffff 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top,  #fffcfc 0%,#2989d8 12%,#2989d8 51%,#207cca 96%,#ffffff 100%); /* IE10+ */
background: linear-gradient(to bottom,  #fffcfc 0%,#2989d8 12%,#2989d8 51%,#207cca 96%,#ffffff 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#fffcfc', endColorstr='#ffffff',GradientType=0 ); /* IE6-9 */

}

DEMO

HERE 是生成CSS渐变最好的工具

关于html - 使用 html/css 在表格的 td 上拉伸(stretch)背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15403400/

相关文章:

html - custom.css 的正确格式

Java-创建瓦片 map gif

javascript - 如何用自己网站的数据填写另一个网站的表格

javascript - 在一个 css 类中设置最大宽度动画

javascript - 避免在元素上绑定(bind)多个事件

html - 为什么第二个导航移动到第一个导航之上

javascript - 在 jquery 库中获取未定义的错误

php - 如何使用 PHP 从数据库中检索图像

php - 从iOS将图像上传到PHP Web服务器

JavaScript 像 jQuery 一样使用 prevAll?