Jill-Jênn Vie
Jill-Jênn Vie

Reputation: 1841

Image background over the lines

I would like to obtain button links with an image over the lines.

I did, actually, using CSS:

section a:link, section a:visited {
    width: 150px;
    -moz-border-radius: 10px;
    -webkit-border-radius: 10px;
    border-radius: 10px;
    -khtml-border-radius: 10px;
    color: white;
    background: #03c;
    padding: 10px 10px 10px 60px;
    display: block;
    text-decoration: none;
}

section div {
    margin-left: 5px;
    margin-top: -9px;
    width: 50px;
    height: 50px;
    float: left;
}

.pdf div {
    background: transparent url('pdf.png') no-repeat 0 50%;
}

Then HTML:

<section class="pdf">
    <div></div>
    <a href="#">Sheet music (PDF)</a>
</section>

But isn't there a better solution than using negative margins that don't work in IE7? I tried to put a certain margin-top into section a tags, but due to collapsing margins, it didn't work.

(Wow, my reputation didn't allow me to embed an image nor add more than 2 external links.)

Upvotes: 2

Views: 182

Answers (2)

Nemanja Srećković
Nemanja Srećković

Reputation: 359

or try something like this, where almost everything is same, but image background is on span tag

<a href="#"><span>Sheet music (PDF)</span></a>

Upvotes: 0

sandeep
sandeep

Reputation: 92873

@jill; in your code you put an image outside the link so when you hover the image then your link hide. i don't know you do it intentionally or not . may be you can use position absolute.

HTML

<a href="#"><span>&nbsp;</span>Sheet music (PDF)</a>

CSS

a{
    display:block;
    position:relative;
    text-decoration:none;
    -moz-border-radius: 10px 10px 10px 10px;    
    background: none repeat scroll 0 0 #0033CC;
    color: white;
    padding: 10px 10px 10px 60px;
    text-decoration: none;
    width: 150px;

}
a span{
    display:block;
    position:absolute;
    background: url("http://www.jill-jenn.net/drafts/background-image-over-the-lines/pdf.png") no-repeat ;
    width:50px;
    height:50px;
    top:-5px;
    left:10px;
}
a:hover{
    background:red;
}

check this example http://jsfiddle.net/sandeep/AwkwF/ may be that's help you

Upvotes: 3

Related Questions