CSS issue with background button
CSS issue with background button
这个问题已经有了答案:
我有一个按钮,上面有一个渐变。我还需要一个图像箭头放在上面,但当我将它放在背景上并且有两个类的按钮时,它似乎无法工作。下面是一个例子:
.btn{ background: rgb(0,166,255); /* Old browsers */ background: -moz-linear-gradient(top, rgba(0,166,255,1) 0%, rgba(0,166,255,1) 50%, rgba(2,154,236,1) 53%, rgba(2,154,236,1) 100%); /* FF3.6+ */ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0,166,255,1)), color-stop(50%,rgba(0,166,255,1)), color-stop(53%,rgba(2,154,236,1)), color-stop(100%,rgba(2,154,236,1))); /* Chrome,Safari4+ */ background: -webkit-linear-gradient(top, rgba(0,166,255,1) 0%,rgba(0,166,255,1) 50%,rgba(2,154,236,1) 53%,rgba(2,154,236,1) 100%); /* Chrome10+,Safari5.1+ */ background: -o-linear-gradient(top, rgba(0,166,255,1) 0%,rgba(0,166,255,1) 50%,rgba(2,154,236,1) 53%,rgba(2,154,236,1) 100%); /* Opera 11.10+ */ background: -ms-linear-gradient(top, rgba(0,166,255,1) 0%,rgba(0,166,255,1) 50%,rgba(2,154,236,1) 53%,rgba(2,154,236,1) 100%); /* IE10+ */ background: linear-gradient(to bottom, rgba(0,166,255,1) 0%,rgba(0,166,255,1) 50%,rgba(2,154,236,1) 53%,rgba(2,154,236,1) 100%); /* W3C */ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00a6ff', endColorstr='#029aec',GradientType=0 ); /* IE6-9 */ border:0px; color:white; font-family: HelveticaNarrow; font-weight: bold; font-size: 12pt; text-transform: uppercase; cursor: pointer; } .btn-wide{ width:728px; height:45px; background-image: url('images/white-arrow-down.png') no-repeat; background-position: 50% 50%; }
我猜是因为.btn类,导致.btn-wide类中的背景被忽略了。
在这个例子中,什么是最好的标记解决方案? 🙂
admin 更改状态以发布 2023年5月22日
点击以下链接获取更新后的fiddle。
我更新了css。
.btn{ background: rgb(0,166,255); /* Old browsers */ background: -moz-linear-gradient(top, rgba(0,166,255,1) 0%, rgba(0,166,255,1) 50%, rgba(2,154,236,1) 53%, rgba(2,154,236,1) 100%); /* FF3.6+ */ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0,166,255,1)), color-stop(50%,rgba(0,166,255,1)), color-stop(53%,rgba(2,154,236,1)), color-stop(100%,rgba(2,154,236,1))); /* Chrome,Safari4+ */ background: -webkit-linear-gradient(top, rgba(0,166,255,1) 0%,rgba(0,166,255,1) 50%,rgba(2,154,236,1) 53%,rgba(2,154,236,1) 100%); /* Chrome10+,Safari5.1+ */ background: -o-linear-gradient(top, rgba(0,166,255,1) 0%,rgba(0,166,255,1) 50%,rgba(2,154,236,1) 53%,rgba(2,154,236,1) 100%); /* Opera 11.10+ */ background: -ms-linear-gradient(top, rgba(0,166,255,1) 0%,rgba(0,166,255,1) 50%,rgba(2,154,236,1) 53%,rgba(2,154,236,1) 100%); /* IE10+ */ background: linear-gradient(to bottom, rgba(0,166,255,1) 0%,rgba(0,166,255,1) 50%,rgba(2,154,236,1) 53%,rgba(2,154,236,1) 100%); /* W3C */ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00a6ff', endColorstr='#029aec',GradientType=0 ); /* IE6-9 */ border:0px; color:white; font-family: HelveticaNarrow; font-weight: bold; font-size: 12pt; text-transform: uppercase; cursor: pointer; position:relative; width:728px; height:45px; } .btn div{ position:absolute; top:0; left:0; right:0; bottom:0; background-image: url('https://cdn4.iconfinder.com/data/icons/ionicons/512/icon-ios7-arrow-right-128.png'); background-position: right; background-repeat:no-repeat; background-size:32px 32px; }
根据您的图片更改箭头图片路径。
问题在于您正在使用background
简写属性,因此尝试应用第二个背景图像只会覆盖之前的语句(渐变)。
您可以使用逗号分隔的背景图像语句,如下所示。
CSS
.btn{ background-image: /* note bg image */ url(http://lorempixel.com/output/abstract-q-c-32-32-2.jpg), linear-gradient(to bottom, rgba(0,166,255,1) 0%,rgba(0,166,255,1) 50%,rgba(2,154,236,1) 53%,rgba(2,154,236,1) 100%); /* W3C */ background-repeat:no-repeat; border:0px; color:white; font-family: HelveticaNarrow; font-weight: bold; font-size: 12pt; text-transform: uppercase; cursor: pointer; background-position:50% 50%; } .btn-wide{ width:728px; height:45px; }