简体   繁体   中英

CSS: Background-image not showing

What am I doing bad?

CSS:

.submit{
padding-left:10px;
margin:0;
border:0;
outline: 0;
height:32px;
padding-right:32px;
}
.green-btn {
background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#61A801), to(#8CC400));
background: -webkit-linear-gradient(top, #8CC400, #61A801);
background: -moz-linear-gradient(top, #8CC400, #61A801);
background: -ms-linear-gradient(top, #8CC400, #61A801);
background: -o-linear-gradient(top, #8CC400, #61A801);
color: #fff;
font-family: verdana;
font-size: 13px;
font-weight: normal;
border-radius:5px;
}
.clipboard{
background-image: url(http://cdn1.iconfinder.com/data/icons/opensourceicons/32/Scissors.png) no-repeat right center;
}
​

HTML:

<input type="submit" value="Copy" class="submit green-btn clipboard">​

JSFiddle: http://jsfiddle.net/77NYA/

You cannot specify the position and repeat values inside the background-image property. You can only specify the URL to the image. You'll have to separate them out like this:

.clipboard {
    background-image: url(http://cdn1.iconfinder.com/data/icons/opensourceicons/32/Scissors.png);
    background-repeat: no-repeat;
    background-position: right center;
}

Also note: Some browsers (I don't know which ones) don't allow gradients and background images to be combined together.


Here's an alternate solution using a <button> with an <img> inside it:

<button type="submit" value="Copy" class="submit green-btn">
    <img src="http://cdn1.iconfinder.com/data/icons/opensourceicons/32/Scissors.png" alt="[scissors]" />
    Copy
</button>​
.submit{
padding-left:10px;
margin:0;
border:0;
outline: 0;
height:32px;
line-height:32px;
padding-right:10px;
}
.green-btn {
background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#61A801), to(#8CC400));
background: -webkit-linear-gradient(top, #8CC400, #61A801);
background: -moz-linear-gradient(top, #8CC400, #61A801);
background: -ms-linear-gradient(top, #8CC400, #61A801);
background: -o-linear-gradient(top, #8CC400, #61A801);
color: #fff;
font-family: verdana;
font-size: 13px;
font-weight: normal;
border-radius:5px;
}
.green-btn img {
float: right;
margin-left: 10px;
}​

And the jsFiddle preview . Feel free to play with the margins and stuff to make it look more how you want.

The linear gradient will be overridden by your background-image once you fix the background-image property.

Best way to do this is to create a div and use linear-gradient on it. Create 2 child elements one which will contain text and other which will contain the icon as background. Make the div behave like a submit button using jquery.

您必须使用background:url(...)而不是background-image

in your .clipboard class remove -image and make it

.clipboard { background: url(http://cdn1.iconfinder.com/data/icons/opensourceicons/32/Scissors.png) no-repeat right center;

}

because 'no-repeat' is value of background-repeat and and 'right center' is value of background-position, and you are using these values in background-image .

so syntex is background: image-src repeat-value image-position

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM