Search code examples
htmlcsspositioning

buttons with pictures - CSS problem


I have a problem positionning a image in a button. Here's a demo http://problem-demo.hit.bg/index.html
I want to position the picture in the middle of the button without pushing the span down. If I set the position to relative the span is being pushed, if I set it to absolute or fixed margin: auto isn't working, if I don't set margin to the span and the image is relative hte spans aren't in one line. Here's the sorce:

<style>
ul {
    list-style: none;
}
ul li {
    margin-left:20px;
    display: inline-block;      
}
ul li a {
    float:left;
    height: 80px;
    width: 80px;
    text-align: center;
    text-decoration: none;
    border: 1px solid black;
}
ul li a span {
    color: gray;
    font-size: 18px;
    position: relative;
    top: 54px;
}
ul li a img {
    position: fixed;
    margin: 20px auto;
    display: block;
}

<ul>
    <li><a href="#"><img src="download.png" alt="something" /><span>Download</span></a></li>
    <li><a href="#"><img src="download.png" alt="something" /><span>Download</span></a></li>
</ul>

Solution

  • You can modify your code like this:

    CSS:

    li {
    background:url(download.png) 20px 20px no-repeat;
    }
    

    HTML:

    <li><a href="#">Download</a></li>