我有一张 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>
...
这是我得到的结果的图像:
因此您可以看到蓝色斜面背景恰好位于每个 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 */
}
HERE 是生成CSS渐变最好的工具
关于html - 使用 html/css 在表格的 td 上拉伸(stretch)背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15403400/