我可以应用多个背景颜色与CSS3吗? [英] Can I apply multiple background colors with CSS3?
问题描述
我知道如何使用CSS3指定多个背景图片,并使用不同的选项修改它们的显示方式。
I know how to specify multiple background images using CSS3 and modify how they are displayed using different options.
目前我有一个
Currently I have a <div>
, which needs to have a different color for about 30% of the width on the left side:
div#content {background: url("./gray.png") repeat-y, white; background-size: 30%;}
这个指定的颜色,并且没有额外的< div>
s?
Instead of loading the image which is totally gray, how can I do this specifying the color, and without additional <div>
s?
推荐答案
你不能真正 - 背景颜色适用于完全的元素背景。
You can’t really — background colours apply to the entirely of element backgrounds. Keeps ’em simple.
您可以为背景定义CSS颜色边界的CSS渐变,例如
You could define a CSS gradient with sharp colour boundaries for the background instead, e.g.
background: -webkit-linear-gradient(left, grey, grey 30%, white 30%, white);
但目前只有少数浏览器支持。请参见 http://jsfiddle.net/UES6U/2/
But only a few browsers support that at the moment. See http://jsfiddle.net/UES6U/2/
(另请参见 http://www.webkit.org/blog / 1424 / css3-gradient / ,了解CSS3渐变的渐变,包括尖锐的颜色边框技巧。)
(See also http://www.webkit.org/blog/1424/css3-gradients/ for an explanation CSS3 gradients, including the sharp colour boundary trick.)
这篇关于我可以应用多个背景颜色与CSS3吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!