【问题标题】:Adding background image to button using CSS使用 CSS 将背景图像添加到按钮
【发布时间】:2012-07-09 23:12:29
【问题描述】:

我正在尝试将背景图像添加到已经具有背景颜色的按钮(或具有相同类的链接)。

这里是 jsfiddle:http://jsfiddle.net/BNvke/

按钮本身看起来很棒,但我正在尝试使它,以便如果我添加某个类,将调整填充并显示背景图像,但图像不显示。这是 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>​

如何才能显示该背景图像?

【问题讨论】:

    标签: html css button


    【解决方案1】:

    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 定义的关于background-color 的规则可以应用于级联

    【讨论】:

      【解决方案2】:
      .button {
          background: url(http://i47.tinypic.com/2ni0ahd.png);
          background-repeat: 3px 5px no-repeat;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-07-06
        • 2019-11-11
        • 1970-01-01
        • 2021-09-05
        • 2020-05-04
        • 1970-01-01
        相关资源
        最近更新 更多