I'm aiming at doing a chess game or actually a chessengine just for the fun of it :-) The easy way to have several chesspieces would be to have one image for each chesspiece but that would be a lot of http-requests which seems unnecessary.
I want to use image from https://commons.wikimedia.org/wiki/File:Chess_Pieces_Sprite.svg
and retrieve the image with background-position and that would not be a problem...
BUT the issue is that the chessboard and it's square are not always the same size (it must be responsive) and I want each sprite to act as a normal image and resize accordingly to the squares.
I've tried with background-size and background-size and wrappers in combinations but obviously I'm missing out something. Maybe it's the wrong approach in this situation? What do you think?
I've also thought about "slicing" the sprite image and create the images from php but I think using css would be a nicer solution.
If I have like this html (which is generated from html) - I would like to view a scaled version of the chesspieces.png (which is 2000x667 in dimension) so it fits in this div and scales accordingly but only shows a portion of the chesspieces.png file, e.g. a rook. I hope you understand what I mean!?
<div style="float:left;background:#ffffff;
width:100px;height:100px;"
class="square"><img src="chesspieces.png">
</div>
Please do tell if you need more information!
UPDATE Thanks for your input!
I've tried with this:
<div style="width:100px;height:100px;background: #ffffff
url('chesspieces2000.png') -20% 40% no-repeat;background-size: cover;
class="square"></div>
What ever I put in in y pos % it does not work. I want the image to fill out the whole square so therefore I'm using background-size:cover
I've also tried background-position-y:40% but nothing happens. I'm able to change ypos with fixed pixel values. Is this supposed to work in this way?
Clarification:
and with this html:
<div class="square"
style="float:left;width:100px;height:100px;background:#000000"><div
style="width:100px;height:100px;background:#000000
url('chesspieces2000.png') 0 0 no-repeat;background-size:100%;"
class="square"></div></div>
And I want to fetch one chesspiece scale it so it covers the square to 100% width and height auto.
UPDATE2:
Thanks to @Robo Robok Thanks!- I solved it, but some mixing with values made it work as I wanted to!
<div style="width:100%;height:100%;
background:#ffffff url('chesspieces2000.png') 19% -10% no-repeat;
background-size:auto 170%;"></div>
and when resizing image wrapper:
This works fine as well. It covers all the square!
<div style="width:100%;height:100%;
background:#ffffff url('chesspieces2000.png') 20% 0% no-repeat;
background-size:auto 200%;"></div>



background-position: 100px 50px;etc. It's much easier if they are consistent width and consistent height. The difference is you have to enter them manually instead of in a loop or something. Make an object in JS{king: [100,200], queen : [200,375]}or what have you.imgtag. Then set the div to a fixed width, set the background to the image, set the position of the part you want. Set no-repeat, etc. etc...