使用CSS添加背景图片按钮(的jsfiddle) [英] Adding background image to button using CSS (jsfiddle)

查看:167
本文介绍了使用CSS添加背景图片按钮(的jsfiddle)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个背景图像添加到按钮(或同一类的链接),它已经有一个背景颜色。

I am trying to add a background image to a button (or link with the same class) which already has a background color.

下面是的jsfiddle: http://jsfiddle.net/BNvke/

Here is the jsfiddle: http://jsfiddle.net/BNvke/

按钮看起来本身不错,但我试图让这个如果我添加一定的阶级,填充将进行调整和背景图像将被显示,但图像不显示。下面是CSS / HTML:

The button looks great by itself, but I am trying to make it so that if I add a certain class, the padding will be adjusted and a background image will be displayed, however the image does not show. Here is the CSS/HTML:

.button {
padding: 10px; 
margin-right: 8px;
margin-bottom:10px;
font-family: Arial, Tahoma, Verdana, FreeSans, sans-serif;
text-shadow:0 1px 1px rgba(0, 0, 0, 0.25);
display: inline-block;
white-space: nowrap;
line-height:1em;
position:relative;
outline: none;
overflow: visible;
cursor: pointer;
border-radius: 4px;
-moz-border-radius: 4px; 
-webkit-border-radius:4px; 
box-shadow:1px 1px 2px 0 #CCCCCC;
-moz-box-shadow: 1px 1px 2px 0 #CCCCCC;
-webkit-box-shadow: 1px 1px 2px 0 #CCCCCC;
}

.button_blue {
border: 1px solid #305875;
color: #FBFBFB;
background-color: #3D6E97;
}

.button_blue:hover {
color: #FBFBFB;
opacity:0.9; 
filter:alpha(opacity=90);        
}

.button_about { 
background-image: url(http://i47.tinypic.com/2ni0ahd.png) 3px 5px no-repeat;
padding-left: 35px;
padding-right: 15px;
}​

-

<p><a class="button button_blue">Without Background</a></p>

<p><a class="button button_blue button_about">With Background</a></p>​

如何能得到背景图像显示?

How can I get that background image to show?

推荐答案

请参见 http://jsfiddle.net/BNvke/1/

只需更改

background-image url(http://i47.tinypic.com/2ni0ahd.png) 3px 5px no-repeat;

background: url(http://i47.tinypic.com/2ni0ahd.png) 3px 5px no-repeat;

和向上移动,最后规则,以便对背景颜色 .button_blue 定义的规则可以适用于级联

and move up the last rule so the rule about background-color defined for .button_blue can be applied on cascade

这篇关于使用CSS添加背景图片按钮(的jsfiddle)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆