html - CSS:背景图像不显示

标签 html css background background-image

我做错了什么?

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/

最佳答案

您不能在 background-image 中指定位置和重复值属性(property)。您可以指定图像的 URL。您必须像这样将它们分开:

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

另请注意:某些浏览器(我不知道是哪些浏览器)不允许将渐变和背景图像组合在一起。


这是使用 <button> 的替代解决方案用<img>里面:

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

还有 jsFiddle preview .随意调整边距和其他东西,让它看起来更像你想要的样子。

关于html - CSS:背景图像不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9780595/

相关文章:

java - 如何拥有透明模糊背景的 JFrame

css - 页面在 Ipad 中不居中

html - 制作一侧 flex 的矩形

javascript - 如何重新定位该对话框?

android - 如何在后台android中运行无限循环

ios - 使用 BGTaskScheduler 进行后台获取可以完美地与调试模拟配合使用,但在实践中却无法使用

javascript - 显示代码时遇到问题

html - 媒体查询不适用于最大宽度屏幕尺寸 (640px)

html - 为什么div不会在上面的div下面向上滑动?

html - CSS Div % 宽度