0

嗨,先生/女士,我想在 td 的顶部和底部有不同的背景,即前半部分应该是绿色,后半部分是红色......

4

4 回答 4

1

使用 CSS 渐变。在您的情况下,CSS 将是:

background-image: linear-gradient(bottom, rgb(0,255,0) 50%, rgb(255,0,0) 50%);
background-image: -o-linear-gradient(bottom, rgb(0,255,0) 50%, rgb(255,0,0) 50%);
background-image: -moz-linear-gradient(bottom, rgb(0,255,0) 50%, rgb(255,0,0) 50%);
background-image: -webkit-linear-gradient(bottom, rgb(0,255,0) 50%, rgb(255,0,0) 50%);
background-image: -ms-linear-gradient(bottom, rgb(0,255,0) 50%, rgb(255,0,0) 50%);

background-image: -webkit-gradient(
    linear,
    left bottom,
    left top,
    color-stop(0.5, rgb(0,255,0)),
    color-stop(0.5, rgb(255,0,0))
);

使用此站点生成更多: http: //gradients.glrzad.com/

于 2013-03-26T11:10:30.480 回答
1

要直接执行此操作,您可以将具有此功能的图像设置为背景。就像是

style="background-image:url(twocolor.png);"
于 2013-03-26T11:10:35.633 回答
0

尝试渐变:

td {
    background: #00ff00;
    background: -moz-linear-gradient(top,  #00ff00 0%, #00ff00 49%, #ff0000 50%, #ff0000 100%);
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#00ff00), color-stop(49%,#00ff00), color-stop(50%,#ff0000), color-stop(100%,#ff0000));
    background: -webkit-linear-gradient(top,  #00ff00 0%,#00ff00 49%,#ff0000 50%,#ff0000 100%);
    background: -o-linear-gradient(top,  #00ff00 0%,#00ff00 49%,#ff0000 50%,#ff0000 100%);
    background: -ms-linear-gradient(top,  #00ff00 0%,#00ff00 49%,#ff0000 50%,#ff0000 100%);
    background: linear-gradient(to bottom,  #00ff00 0%,#00ff00 49%,#ff0000 50%,#ff0000 100%);
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00ff00', endColorstr='#ff0000',GradientType=0 );
}

要编辑此渐变,请使用.

于 2013-03-26T11:10:28.227 回答
0

以防你不喜欢渐变(只是为了好玩)。http://codepen.io/anon/pen/mqdvB

于 2013-03-26T11:14:20.443 回答