html - how to position a css sprite as background for another class -
sorry if layout of question seems weird, i've wrote question 10 times on , on again in editor, resulting in getting error message "unformatted code found etc." - removed code , placed picture examples. (2 hours simple question)
hello folks! have .png image, containing several icons works css sprite. creation of each css class no problem use generator that. (works charm)
problem is, want use, example: created .iconinfo_32
class, background
property another css class.
what want achive?
simple said, custom css - messagebox, icon on left side. icon in original sprite containing multiple icons. that's problem starts.
what have
the icons
(thats 1 png)
the icon want use
how result should like
how looks
use div, in div
yes, work - i'd have "one" css class, without need put div, div, position should , on - had problems position of div.
i've provided source example, being able understand question , goal. excuse me if layout of question unusual , unpleasent, have done in way, editor won't let me
source
html
<div class="warning_without_sprite"> div container<br /> showing error message use of 'close_32.png' icon. (no sprite) </div><br /><br /><br /><br /> <div class="warning_with_sprite"> div container<br /> showing error message use of 'icons.png' icon. (sprite) </div>
css
<style type="text/css"> .iconinfo_32 { width: 32px; height: 32px; background:url(images/icons.png) no-repeat -0px -0px; } .iconok_32 { width: 32px; height: 32px; background:url(images/icons.png) no-repeat -32px -0px; } .iconadd_32 { width: 32px; height: 32px; background:url(images/icons.png) no-repeat -64px -0px; } .iconclose_2_32 { width: 32px; height: 32px; background:url(images/icons.png) no-repeat -96px -0px; } .iconclose_32 { width: 32px; height: 32px; background:url(images/icons.png) no-repeat -128px -0px; } .icondelete_32 { width: 32px; height: 32px; background:url(images/icons.png) no-repeat -160px -0px; } .icondownload_32 { width: 32px; height: 32px; background:url(images/icons.png) no-repeat -192px -0px; } .iconhelp_32 { width: 32px; height: 32px; background:url(images/icons.png) no-repeat -224px -0px; } .warning_without_sprite { border: 1px solid; padding: 10px 10px 10px 50px; background-repeat: no-repeat; background-position: 10px center; float:left; color: #d8000c; background-color: #ffbaba; background-image: url('images/close_32.png'); } .warning_with_sprite { border: 1px solid; padding: 10px 10px 10px 50px; background-repeat: no-repeat; background-position: 10px center; float:left; color: #d8000c; background: #ffbaba url('images/icons.png') no-repeat -128px -0px; } </style>
it's because you've set background-image across whole <div>
element , because sprite contains multiple images show them all. can't specify how of sprite show.
you'll have insert <span>
element <div>
. allow specify size of span , position relative div container.
<div class="warning"> <span class="warning_with_sprite"></span> div container<br /> showing error message use of 'icons.png' icon. (sprite) </div>
css:
.warning_with_sprite { position:absolute; left:16px; top:16px; background-repeat: no-repeat; background-position: 10px center; width:20px; height:20px; background: url('http://i5.minus.com/id1cyq.png') no-repeat -133px -2px; } .warning { float:left; color: #d8000c; border: 1px solid; position:relative; padding: 10px 10px 10px 50px; background: #ffbaba; }
see demo here
note: you'll have change image sprite , top, left, height , width properties have change inline requirements
Comments
Post a Comment