Add image left and right to link with CSS class

2932 views css

i need to add an small image to the left and right from a hyperlink. This will be reused several times with different images, so I need to do it in CSS with classes. I succeeded already to either the left

.fuss {background: transparent url( center left no-repeat; padding-left: 20px;}     

or to the right

.fuss {background: transparent url( center right no-repeat; padding-right: 20px;}

but as soon i try to use two classes for left AND right, it didnt work, only one image shows up:

.fuss-rechts {background: transparent url( right no-repeat; padding-right: 20px;}
.fuss-links {background: transparent url( left no-repeat; padding-left: 20px;}

 in HTML: <a class="fuss-links fuss-rechts" target="_blank" href="">hier mein link</a>

Any help appreciated! Thank you

answered question

2 Answers


Yes, this is expected behavior. The CSS class fuss-links is overwriting the background rule set by fuss-rechts since it comes 2nd in the stylesheet, since CSS rulesets prioritize rules that come last (hence the C for cascading in CSS).

To my knowledge, you cannot achieve the desired effect using just the CSS background rule, since it does not allow you to repeat elements only on the edges, you can either never repeat or repeat across the entire width (source:

My suggestion would be to move the images to <img> tags inside the <a> tag and to use position: absolute; to achieve the effect you want. You can see any example here:

posted this

Your css class should be this:

    .fuss {
       background: transparent;
       background-image: url(, url(;
       background-repeat: no-repeat, no-repeat;

posted this

Have an answer?


Please login first before posting an answer.