Question

I have a button, that has a gradient on it. I also needs an image arrow on it, but when I put it to background, and a button with two classes it seems not to work. Below is an example:

<button class="btn btn-wide">Load more</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%;
}

The background at the class .btn-wide is getting ignored because of the .btn class I guess. What would be the best markup solution in this example? :)

Jsfiddle

Was it helpful?

Solution

The issue is that you are using the background shorthand property so trying to apply a second background image merely overwrites the previous statement (the gradient).

You can use comma separated background image statements like this.

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;

}

JSFiddle Demo

OTHER TIPS

Find the following link for updated fiddle.

FIDDLE

I updated the 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;
}



Change the arrow image path according to your image.

The problem is with this rule

background-image: url('images/white-arrow-down.png') no-repeat;

you're specifying repeat in background-image.

You can rewrite it as

background-image: url('images/white-arrow-down.png');
background-repeat:  no-repeat;

Update:

Fixing actual issue in your CSS doesn't provide you with your desired results because backgorund-image is going to overwrite the gradient. You can add position: relative .btn, remove background from .btn-wide, and use :before pseudo selector to add an element to your button. Following is the 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;;
     }

     .btn-wide{
        width: 728px;
        height: 45px;
     }

     .btn-wide:before{
        content: ' ';
        display: block;
        height: 100%;
        width: 100%;
        position: absolute;
        background: url('images/white-arrow-down.png') no-repeat 50% 50%;
        top: 0;
        left: 0;
     }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top