将图像添加到自定义按钮

时间:2014-06-08 21:27:24

标签: html css htmlbutton

您好我在使用以下css创建自定义按钮

    .myBlackButton02 {
    -moz-box-shadow:inset 0px -3px 7px 0px #6a6f76;
    -webkit-box-shadow:inset 0px -3px 7px 0px #6a6f76;
    box-shadow:inset 0px -3px 7px 0px #6a6f76;
    background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #61656c), color-stop(1, #292b2e));
    background:-moz-linear-gradient(top, #61656c 5%, #292b2e 100%);
    background:-webkit-linear-gradient(top, #61656c 5%, #292b2e 100%);
    background:-o-linear-gradient(top, #61656c 5%, #292b2e 100%);
    background:-ms-linear-gradient(top, #61656c 5%, #292b2e 100%);
    background:linear-gradient(to bottom, #61656c 5%, #292b2e 100%);
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#61656c', endColorstr='#292b2e',GradientType=0);
    background-color:#61656c;
    -moz-border-radius:3px;
    -webkit-border-radius:3px;
    border-radius:3px;
    border:1px solid #040405;
    display:inline-block;
    cursor:pointer;
    color:#ffffff;
    font-family:Tahoma;
    padding:9px 23px;
    text-decoration:none;
    text-shadow:0px 1px 0px #263666;
}
.myBlackButton02:hover {
    background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #292b2e), color-stop(1, #61656c));
    background:-moz-linear-gradient(top, #292b2e 5%, #61656c 100%);
    background:-webkit-linear-gradient(top, #292b2e 5%, #61656c 100%);
    background:-o-linear-gradient(top, #292b2e 5%, #61656c 100%);
    background:-ms-linear-gradient(top, #292b2e 5%, #61656c 100%);
    background:linear-gradient(to bottom, #292b2e 5%, #61656c 100%);
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#292b2e', endColorstr='#61656c',GradientType=0);
    background-color:#292b2e;
}
.myBlackButton02:active {
    background:transparent;
}

我正在使用的html是

<div id="d1" style="height:46px;top:0px;left:0px;right:0px;" class="heading01" >
        <div id="d2" class="style1" style="position:absolute;left:10px;top:4.5px;color:#FFF;">Heading</div>

        <div align="right" style="padding-top:2.5px;padding-right:10px;">

            <button class="myBlackButton02" style="font-size:10pt;outline:none;"> x </button>
            <button class="myBlackButton02" style="font-size:10pt;outline:none;"> x </button>


            <button class="myBlackButton02" style="font-size:10pt;outline:none;">
                <img src="icons/extensions/right_16.png" style=""/> 
            </button>
</div>

和heading01的css是

.heading01{
    background: rgb(69,72,77); /* Old browsers */
background: -moz-linear-gradient(top,  rgba(69,72,77,1) 0%, rgba(0,0,0,1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(69,72,77,1)), color-stop(100%,rgba(0,0,0,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top,  rgba(69,72,77,1) 0%,rgba(0,0,0,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top,  rgba(69,72,77,1) 0%,rgba(0,0,0,1) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top,  rgba(69,72,77,1) 0%,rgba(0,0,0,1) 100%); /* IE10+ */
background: linear-gradient(to bottom,  rgba(69,72,77,1) 0%,rgba(0,0,0,1) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#45484d', endColorstr='#000000',GradientType=0 ); /* IE6-9 */
}

与我得到的是

enter image description here

但我想要的是所有按钮处于相同的垂直高度。我知道有办法做到这一点,但我不知道如何做。所以任何帮助将不胜感激。我甚至尝试通过将图像设置为背景图像来实现它,但是渐变变成了纯色,甚至尝试使用div,但它与图像相同。感谢

3 个答案:

答案 0 :(得分:1)

你在html的末尾缺少一个结束div标签。此外,删除填充并设置按钮的宽度和高度。如前所述,将垂直对齐设置为中间。 See here

简化CSS:

.myBlackButton02 {
    /*padding:9px 23px;*/
    width: 80px;
    height: 80px;
    vertical-align: middle;
    margin-right: 10px;
}

答案 1 :(得分:0)

在你的css中设置一个margin-top:x px;对于每一个,这应该使他们所有水平。祝你好运

答案 2 :(得分:0)

您应该将下一个代码添加到.myBlackButton02 CSS:

vertical-align: middle;
width: 50pt;
height: 30pt;

您必须根据图像定义首选按钮宽度和高度。