为什么背景图像在按钮中被截断

时间:2014-07-22 19:43:41

标签: html css image

<a class="button icon tag" href="#"><span>Show All Tasks</span></a>

a.button {
    background-image: -moz-linear-gradient(top, #ffffff, #dbdbdb);
    background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0, #ffffff),color-stop(1, #dbdbdb));
    filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='#ffffff', EndColorStr='#dbdbdb');
    -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorStr='#ffffff', EndColorStr='#dbdbdb')";
    border: 1px solid #fff;
    -moz-box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.4);
    -webkit-box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.4);
    box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.4);
    border-radius: 3px;
    -webkit-border-radius: 3px;
    -moz-border-radius: 3px;
    padding: 10px 20px;
    text-decoration: none;
    text-shadow: #fff 0 1px 0;
    float: left;
    display: block;
    color: #597390;
    line-height: 24px;
    font-size: 20px;
    font-weight: bold;
    width: 100%;
}

a.button:hover {
    background-image: -moz-linear-gradient(top, #ffffff, #eeeeee);
    background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0, #ffffff),color-stop(1, #eeeeee));
    filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='#ffffff', EndColorStr='#eeeeee');
    -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorStr='#ffffff', EndColorStr='#eeeeee')";
    color: #000;
    display: block;
}

a.button:active {
    background-image: -moz-linear-gradient(top, #dbdbdb, #ffffff);
    background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0, #dbdbdb),color-stop(1, #ffffff));
    filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='#dbdbdb', EndColorStr='#ffffff');
    -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorStr='#dbdbdb', EndColorStr='#ffffff')";
    text-shadow: 0px -1px 0 rgba(255, 255, 255, 0.5);
    margin-top: 1px;
}

a.button.icon {
    padding-left: 0px;
}

a.button.icon span{
    padding-left: 100px;
    background: url(icons2.png) no-repeat 0 -4px;
}

a.button.icon.tag span {
    background-position: 0px -65px;
}

图像(icons2 40X96):

enter image description here

如何在浏览器中显示:

enter image description here

如何显示整个图像以使其不会被切断? 由于它只是一个图像,我如何消除位置的用户,而只是显示图像?

2 个答案:

答案 0 :(得分:2)

只需提供范围display:block;height:30px;

a.button.icon span{
    padding-left: 100px;
    background: url(http://i.stack.imgur.com/fEeuO.png) no-repeat 0 -4px;
    height:30px;
    display:block;
}

为了停止切断,我稍微改变了背景位置:

a.button.icon.tag span {
    background-position: 0px -62px;
}

enter image description here

JSFiddle

答案 1 :(得分:0)

我猜你的行高属性限制了图像的显示量。还可以尝试添加溢出:对图标的容器可见。