【发布时间】:2013-12-19 09:21:03
【问题描述】:
我正在使用 CSS 创建自定义(渐变)按钮。单击按钮时,它应该出现小箭头(arrow.gif)。它在我使用 background-color: 属性之前有效。现在我使用:
a.nav_selected:link, a.nav_selected:visited {
display:block;
float:left;
padding:0px;
margin:0;
width: auto;
margin:0px 14px 0px 14px;
text-align:center;
text-decoration:none;
color: black;
margin:0px 0px 0px 0px;
padding:0px 14px 0px 14px;
background:url(images/arrow.gif) no-repeat top center;
background-image: -o-linear-gradient(bottom, #FCBA2A 0%, #FFE3A3 100%);
background-image: -moz-linear-gradient(bottom, #FCBA2A 0%, #FFE3A3 100%);
background-image: -webkit-linear-gradient(bottom, #FCBA2A 0%, #FFE3A3 100%);
background-image: -ms-linear-gradient(bottom, #FCBA2A 0%, #FFE3A3 100%);
opacity: 0.85;
}
如果我在代码底部使用background:url(images/arrow.gif) no-repeat top center;(在 background-image:... 之后),则会出现箭头,但这里没有渐变背景。如何使其出现以及箭头和背景?谢谢。
更新
现在我的代码如下所示:
a.nav_selected:link, a.nav_selected:visited {
display:block;
float:left;
padding:0px;
margin:0;
width: auto;
margin:0px 14px 0px 14px;
text-align:center;
text-decoration:none;
color: black;
margin:0px 0px 0px 0px;
padding:0px 14px 0px 14px;
background-image: -o-linear-gradient(bottom, #FCBA2A 0%, #FFE3A3 100%);
background-image: -moz-linear-gradient(bottom, #FCBA2A 0%, #FFE3A3 100%);
background-image: -webkit-linear-gradient(bottom, #FCBA2A 0%, #FFE3A3 100%);
background-image: -ms-linear-gradient(bottom, #FCBA2A 0%, #FFE3A3 100%);
opacity: 0.85;
position: relative;
}
a.nav_selected:link:after,
a.nav_selected:visited:after {
position: absolute;
right: 2px;
top: 7px;
content: '';
display: block;
background:url(images/arrow.gif) no-repeat top center;
}
但我遇到了同样的问题,只出现了渐变背景,这里没有动画箭头。
【问题讨论】:
-
你用
background-image覆盖background:url(images/arrow.gif) no-repeat top center; -
没有跨浏览器的方法来使用多个背景图像。浏览器将渐变视为背景图像。
-
谢谢你的回答,所以没有办法做到这一点?
-
@RimantėBaltiejūtė 请查看我的答案和相关的 jsFiddle。
标签: image css background gradient