Hello guys,
Maybe someone can help me...
I want to replace my img tags in my site with css image sprites.
The problem is that I only know how to do it with all images with same size, and my sprite image have lots of images with different sizes.
Can someone teach me?
I'm using a transparent png image with all my images there and I use this code in my css file:
First I was thinking in using this code:
But than, I notice that I cant create a hyperlink right? Because I cant use href tag.
Than I thought in this one:
But where I put the background-position? Inside mainimg css too?
And how can I display another image with a different size? If the code already have the (height and width).
I know I can create many .mainimg, like .mainimg2, .mainimg3, etc...
But I dont want to have a big css file with lots of lines.
Is not possible to create new css lines only with the sizes? something like this:
If yes, how do I need to put the code to show different images?
I thought that I was possible to use like this:
But is not working...
What Im doing wrong?
Please help!
Hope you can understand my explanation, and sorry for my poor english.
Maybe someone can help me...
I want to replace my img tags in my site with css image sprites.
The problem is that I only know how to do it with all images with same size, and my sprite image have lots of images with different sizes.
Can someone teach me?
I'm using a transparent png image with all my images there and I use this code in my css file:
PHP:
.mainimg {
background: url(/images/spritesheet.png);
display: inline-block;
margin-right: 0;
position: relative;
height: 160px;
width: 40px;
}
First I was thinking in using this code:
PHP:
<span style="background-position: -132px -100px;" class="mainimg"></span>
But than, I notice that I cant create a hyperlink right? Because I cant use href tag.
Than I thought in this one:
PHP:
<a href="#" class="mainimg"></a>
But where I put the background-position? Inside mainimg css too?
And how can I display another image with a different size? If the code already have the (height and width).
I know I can create many .mainimg, like .mainimg2, .mainimg3, etc...
But I dont want to have a big css file with lots of lines.
Is not possible to create new css lines only with the sizes? something like this:
PHP:
.mainimg {
background: url(/images/spritesheet.png);
display: inline-block;
margin-right: 0;
position: relative;
}
PHP:
.image1 {
height: 160px;
width: 40px;
}
PHP:
.image2 {
height: 101px;
width: 27px;
}
If yes, how do I need to put the code to show different images?
I thought that I was possible to use like this:
PHP:
<a href="#" class="mainimg image1"></a>
But is not working...
What Im doing wrong?
Please help!
Hope you can understand my explanation, and sorry for my poor english.