将图像放在Html中的按钮上

时间:2015-10-05 12:00:50

标签: html css css3

我想设计一个像

这样的按钮

enter image description here

我编写了一个创建按钮的代码

CSS

 .button {
        color: white;
        width: 10%;
        font-size: 15pt;
        padding: .5em 1em;
        cursor: pointer;
        box-shadow: 2px 2px 5px hsla(0,0%,0%,.7);
        text-shadow: 0px 0px 1px hsla(0,0%,0%,.8);
        border-radius: 5px;
        margin: 1em;
        background-image: -webkit-radial-gradient(50% 0%,160% 100%,hsla(0,0%,100%,.3),hsla(0,0%,100%,.3) 50%,hsla(0,0%,100%,0) 52%, hsla(0,30%,400%,0));
        background-color: orange;
        text-align: right;
        display: inline-block;
    }

    img {
        margin-top: -35%;
        margin-left: -20%;
        display: block;
    }

HTML

<button class="button"><img src="img/Play.png" />Play</button>

但是resualt是

enter image description here

任何人都可以帮我,我怎么把img放在左边的按钮上?

2 个答案:

答案 0 :(得分:3)

请使用此代码: CSS:

<style>

    .button {
        color: white;
        width: 210px;
        height: 35px;
        text-align: left;
        border: 0px;
        font-size: 15pt;
        padding: 0 0 0 65px;
        cursor: pointer;
        box-shadow: 2px 2px 5px hsla(0,0%,0%,.7);
        text-shadow: 0px 0px 1px hsla(0,0%,0%,.8);
        border-radius: 5px;
        background: -webkit-linear-gradient(left, #cdb060 0%,#a5862e 100%); /* Chrome10+,Safari5.1+ */
        background-color: orange;
    }

    img {
        display: block;
        left: 0;
        position: absolute;
        top: -2%;
        z-index: 1;
    }
</style>

和HTML:

<body>
   <button class="button">Play Trauker</button>
   <img src="img/play-stop.png" />
</body>

答案 1 :(得分:1)

您可以将absolute position用于图片。

.button {
        position:relative;
    }
img {
        display: inline-block;
        width:20px;
        height:70px;
        position:absolute;
        left:2px;
        top:-13px
    }

jsfiddle link