Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can try this: <a href="http://www.guistuff.com/css/css_imagetech1.html" rel="nofollow noreferrer">http://www.guistuff.com/css/css_imagetech1.html</a></p> <h2>Cropping X and Y</h2> <p>That first image was kind of a softball. All the cool kids know how to take advantage of cropping an image in both axes. There are several reasons for doing this: You may have images of different sizes and want to place all of them within one file, for example. If you only crop on one axis, you'd be saving a file with the largest possible width or height of the array of images you want to use. Also, there are compression elements that you may want to take advantage of in the PNG file format, like keeping images with the same background color in the same horizontal row, and then having several rows. Whatever the reason, there actually isn't much more to this than what we've seen so far. Here's another example image:</p> <p><img src="https://i.stack.imgur.com/XhqdK.png" alt="icons"></p> <pre><code>.icons { display: block; width: 40px; height: 40px; background-image: url(images/sixicons.png); background-repeat: no-repeat; } </code></pre> <p>You can deduce from this class that the width and height of each icon is 40 pixels, and that the image file name is sixicons.png. I didn't create a very challanging example this time for X/Y cropping in the sense that all of the sub-images are of the same size. As you'll see, however, even if they weren't, you'd still be using a simimlar (though not exact) technique.</p> <p>First, let's crop the top-left icon:</p> <pre><code>.icon_1 { background-position: 0px 0px; } </code></pre> <p>The markup would be:</p> <pre><code>&lt;span class="icons icon_1"&gt;&lt;/span&gt; </code></pre> <p>That was, of course, the easiest one. Now let's say we want the middle-bottom icon:</p> <pre><code>.icon_5 { background-position: -40px -40px; } </code></pre> <p>Let's see the CSS for all of the icons:</p> <pre><code>.icon_1 { background-position: 0px 0px; } .icon_2 { background-position: -40px 0px; } .icon_3 { background-position: -80px 0px; } .icon_4 { background-position: 0px -40px; } .icon_5 { background-position: -40px -40px; } .icon_6 { background-position: -80px -40px; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload