【发布时间】:2011-08-06 14:40:54
【问题描述】:
今天我正在设计一个透明的 PNG 背景,它只会位于 div 的左上角,而 div 的其余部分将为 PNG 的所有透明区域以及 div 本身的其余部分保持渐变背景。
最好通过我认为可行的代码来解释:
#mydiv .isawesome {
/* Basic color for old browsers, and a small image that sits in the top left corner of the div */
background: #B1B8BD url('../images/sidebar_angle.png') 0 0 no-repeat;
/* The gradient I would like to have applied to the whole div, behind the PNG mentioned above */
background: -moz-linear-gradient(top, #ADB2B6 0%, #ABAEB3 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#ADB2B6), color-stop(100%,#ABAEB3));
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ADB2B6', endColorstr='#ABAEB3',GradientType=0 );
}
我发现大多数浏览器会选择其中一个 - 大多数选择渐变,因为它位于 CSS 文件的下方。
我知道这里的一些人会说“只需将渐变应用到您正在制作的 PNG 上” - 但这并不理想,因为 div 将保持动态高度 - 有时非常短,有时非常高。我知道这个渐变不是必要的,但我认为可能值得问问你们大家的想法。
是否可以有背景图片,同时将背景的其余部分保持为渐变?
【问题讨论】:
标签: image background css gradient