7

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

3
  • Can you please create a fiddle for your code? That'll help. Commented May 7, 2014 at 12:22
  • I just updated my post :-) Commented May 7, 2014 at 12:24
  • You can include an icon next to your text inside the button tag using the <i> class. Commented May 7, 2014 at 12:34

3 Answers 3

6

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

Sign up to request clarification or add additional context in comments.

3 Comments

this adds background image to .btn. OP ony want background image added to .btn-wide
Then he's SOL. AFAIK.
@Simon Dunn: Here the image arrow is in the centre of the button
1

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.

Comments

0

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;
     }

2 Comments

This does not seems to be the issue. If i try your example, it only shows the arrow, and not the gradient. Is should show both :-)
background-image is going to replace the gradient.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.