css - How do I use a sprite background image to display once on an element (no-repeat)? -


i wish add jquery icon class added plugin (jquery.tablesorter.js), wish add icon ui-icon-triangle-1-n .headersortup class tablesorter.

i trying add following class can't life of me how work out sprite it.

table.sortable thead tr .headersortup {   cursor: pointer;   background-position: center right;   background-repeat: no-repeat;   background-size: 16px 16px;   background: url(jquery-ui/css/smoothness/images/ui-icons_222222_256x240.png) 0 -16px; } 

i've not worked css sprites before not entirely sure how this.

the situation see want portion of background image appear, want positioned right center of text , no-repeat.

there excellent tutorial on background image crop sprites here: css-background-image-hacks

the trick use pseudo selectors :after or :before place icon header without having add additional element html structure.

and here add working demo using tablesorter plugin: http://jsfiddle.net/fxq8b/

.tablesorter thead tr {   line-height:16px;   background-color:#ddd;   cursor: pointer; } .headersortup:after, .headersortdown:after {    content:"";    float:right;    width:16px;    height:16px;    margin:0 5px 0 0;    background:url('http://www.wooldalejunior.org.uk/ui/vendor/jquery.ui/css/smoothness/images/ui-icons_222222_256x240.png');    background-position:0 -16px; } .headersortdown:after {    background-position:-64px -16px; } 

now need move many times x 16px left , reach desired icons (for example ... -> background-position: 0 -48px; down -> background-position: -64px -48px ... or -> background-position: -96px -192px; down -> background-position: -64px -192px, need count how many icons top , left edge desired icon lies on image: http://jsfiddle.net/fxq8b/1/).


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -