3 ways-to-create-sprites-in-rails

Nico Hagenburger
Nico HagenburgerRails developer, Web designer, Haml and Sass fan um home
3 Ways to Create
  CSS Sprites
   With Rails
What Are Image
Sprites?
A great way to save
  HTTP requests.
In other words:

 Something that
makes your website
     faster. awes om
                     e!
3 ways-to-create-sprites-in-rails
Rails 3.1 > Integrated Spriting
CSS_Sprite > better <img>
Lemonade > Full CSS sprites
Finding Information




  http://www.drdobbs.com/blog/archives/2010/06/preparing_for_r.html
Few Information




http://blog.endpoint.com/2010/06/rails-3-at-railsconf-2010-code-goodness.html
A Piece of Code




   http://twitter.com/jsiarto/status/15861245321
Finally!


   http://www.rubyinside.com/dhhs-railsconf-2010-keynote-video-a-justification-of-rails-3-0-3325.html
Generation Sprites
<%= sprite_css("icons") %>



★   Combines all images of a folder
★   Generates CSS
Using Images
<%= sprite_tag("icons/trash") %>



★   Adds a HTML tag with the class
                (I guess it works this way.)
Questions
★   Is it possible to pack CSS files?
★   Why “icons/trash” if image_tag requires
    “icons/trash.png”?
★   When will it be available?
Rails 3.1 > Integrated Spriting
CSS_Sprite > better <img>
Lemonade > Full CSS sprites
gem install
css_sprite
Features
★   Creates sprite images
★   Creates classes for each file
★   Sass compatible
★   Rake Task for generation
From Image to CCS
images under css_sprite directory                             class name in css_sprite css

twitter_icon.png                                              .twitter_icon

facebook_icon.png                                             .facebook_icon

hotmail-logo.png                                              .hotmail-logo

gmail-logo.png                                                .gmail-logo

icons/twitter_icon.png                                        .icons .twitter_icon

widget/icons/twitter_icon.png                                 .widget .icons .twitter_icon

twitter_icon_hover.png                                        .twitter_icon:hover

twitter-icon-hover.png                                        .twitter-icon:hover

logos_hover/gmail_logo.png                                    .logos:hover .gmail_logo

logos-hover/gmail-logo.png                                    .logos:hover .gmail-logo

…                                                             …




                                    full table at http://github.com/flyerhzm/css_sprite
Built Sprites (1)
rake css_sprite:build
Built Sprites (2)
rake css_sprite:start
Pros
★   Easy for HTML developers
★   Easy if you’re handling <img> tag
Cons
★   A lot of CSS generated (sizes, …)
★   Additional non-semantic tags
★   Additional classes
★   Positioned background images difficult
★   RMagick
★   Rake task
Alternatives
★   http://github.com/gistinc/sprite
    based on css_sprite
★   http://github.com/sblackstone/auto_sprite
    image_tag extention + CSS classes
★   http://github.com/setepo/css-sprites
    image_tag extention + inline CSS
Rails 3.1 > Integrated Spriting
CSS_Sprite > better <img>
Lemonade > Easy Sprites
3 ways-to-create-sprites-in-rails
gem install
 lemonade
Simple Sprites
.add {
  background:
    sprite-image("icons/pl.png");
}

.remove {
  background:
    sprite-image("icons/rm.png");
}
               all icons by p.yusukekamiyamane.com (CC by 3.0)
Output
.add {
  background:
    url("icons.png");
}

.remove {
  background:
    url("icons.png") 0 -16px;
}
Right Aligned
.something {
  background:
    sprite-image("i/wide.png");
}
a.next {
  background: yellow no-repeat
    sprite-image("i/n.png", 100%);
  padding-right: 20px;
}
Result
.something {
  background:
    url("i.png");
}
                  Example link
a.next {
  background: yellow no-repeat
    url("i.png") 100% -20px;
  padding-right: 20px;
}
Empty Space
.add {
  background:
    sprite-image("icons/pl.png");
}
.remove {
  background: yellow no-repeat
    sprite-image("icons/rm.png");
  padding: 20px;
}
Could be Better
.add {
  background:
    url("icons.png");
}
.remove {             Example link
  background:
    url("icons.png") 0 -16px;
  padding: 20px;
}
Empty Space
.add {
  background:
    sprite-image("icons/pl.png");
}
.remove {
  background: yellow no-repeat
    sprite-image("icons/rm.png",
       0, 0, 20px);
  padding: 20px; }
Just Perfect
.add {
  background:
    url("icons.png");
}
.remove {             Example link
  background:
    url("icons.png") 0 -36px;
  padding: 20px;
}
Sprite Generation
★   Sprite image named by directory:
    “icons/*.png” > “icons.png”

★   Background position added only if needed

★   Add “no-repeat” by yourself:
    background:
      sprite-image("…") no-repeat;
Any questions?
Happy forking:
http://github.com/flyerhzm/css_sprite
http://github.com/hagenburger/lemonade
last name
first name


             nico@hagenburger.net
    e-mail
              twitter
                        blog
1 von 37

Recomendados

3 Steps to Make Better & Faster Frontends von
3 Steps to Make Better & Faster Frontends3 Steps to Make Better & Faster Frontends
3 Steps to Make Better & Faster FrontendsNico Hagenburger
4K views37 Folien
Big Frontends Made Simple von
Big Frontends Made SimpleBig Frontends Made Simple
Big Frontends Made SimpleNico Hagenburger
3.3K views51 Folien
Rapid Prototyping FTW!!! von
Rapid Prototyping FTW!!!Rapid Prototyping FTW!!!
Rapid Prototyping FTW!!!cloudbring
991 views63 Folien
Revolver von
RevolverRevolver
RevolverMichelle Lim
106 views11 Folien
CSS Preprocessors: LESS is more or look SASS-y trying von
CSS Preprocessors: LESS is more or look SASS-y tryingCSS Preprocessors: LESS is more or look SASS-y trying
CSS Preprocessors: LESS is more or look SASS-y tryingJames Cryer
1.9K views19 Folien
Scaling Rails Sites by default von
Scaling Rails Sites by defaultScaling Rails Sites by default
Scaling Rails Sites by defaultYi-Ting Cheng
1K views46 Folien

Más contenido relacionado

Was ist angesagt?

Write LESS. DO more. von
Write LESS. DO more.Write LESS. DO more.
Write LESS. DO more.Eugene Nor
658 views30 Folien
Variations on a Theme von
Variations on a ThemeVariations on a Theme
Variations on a ThemeCommercial Progression
1.2K views54 Folien
CSS Grid Layout von
CSS Grid LayoutCSS Grid Layout
CSS Grid LayoutRachel Andrew
128.2K views120 Folien
Big Design Conference: CSS3 von
Big Design Conference: CSS3 Big Design Conference: CSS3
Big Design Conference: CSS3 Wynn Netherland
1.7K views141 Folien
Traceur - Javascript.next - Now! RheinmainJS April 14th von
Traceur - Javascript.next - Now! RheinmainJS April 14thTraceur - Javascript.next - Now! RheinmainJS April 14th
Traceur - Javascript.next - Now! RheinmainJS April 14thCarsten Sandtner
2.1K views21 Folien
Intro to CouchDB von
Intro to CouchDBIntro to CouchDB
Intro to CouchDBbenaldred
591 views38 Folien

Was ist angesagt?(20)

Write LESS. DO more. von Eugene Nor
Write LESS. DO more.Write LESS. DO more.
Write LESS. DO more.
Eugene Nor658 views
Traceur - Javascript.next - Now! RheinmainJS April 14th von Carsten Sandtner
Traceur - Javascript.next - Now! RheinmainJS April 14thTraceur - Javascript.next - Now! RheinmainJS April 14th
Traceur - Javascript.next - Now! RheinmainJS April 14th
Carsten Sandtner2.1K views
Intro to CouchDB von benaldred
Intro to CouchDBIntro to CouchDB
Intro to CouchDB
benaldred591 views
Accelerated Native Mobile Development with the Ti gem von Wynn Netherland
Accelerated Native Mobile Development with the Ti gemAccelerated Native Mobile Development with the Ti gem
Accelerated Native Mobile Development with the Ti gem
Wynn Netherland954 views
LESS von Joe Seifi
LESSLESS
LESS
Joe Seifi13.4K views
Capybara von Mona Soni
CapybaraCapybara
Capybara
Mona Soni1.9K views
Introducing grunt, npm and sass von priyanka1452
Introducing grunt, npm and sassIntroducing grunt, npm and sass
Introducing grunt, npm and sass
priyanka1452274 views
Obscure Wordpress Functions That Are Actually Quite Useful von Graham Armfield
Obscure Wordpress Functions That Are Actually Quite UsefulObscure Wordpress Functions That Are Actually Quite Useful
Obscure Wordpress Functions That Are Actually Quite Useful
Graham Armfield801 views
Perch, Patterns and Old Browsers von Rachel Andrew
Perch, Patterns and Old BrowsersPerch, Patterns and Old Browsers
Perch, Patterns and Old Browsers
Rachel Andrew1.8K views
LESS(CSS preprocessor) von VIPIN KUMAR
LESS(CSS preprocessor)LESS(CSS preprocessor)
LESS(CSS preprocessor)
VIPIN KUMAR696 views
Getting Started with Sass & Compass von Rob Davarnia
Getting Started with Sass & CompassGetting Started with Sass & Compass
Getting Started with Sass & Compass
Rob Davarnia1.8K views
Confoo: You can use CSS for that! von Rachel Andrew
Confoo: You can use CSS for that!Confoo: You can use CSS for that!
Confoo: You can use CSS for that!
Rachel Andrew1.5K views
Sass, Compass and the new tools - Open Web Camp IV von Dirk Ginader
Sass, Compass and the new tools - Open Web Camp IVSass, Compass and the new tools - Open Web Camp IV
Sass, Compass and the new tools - Open Web Camp IV
Dirk Ginader3.1K views
Locarise,reagent and JavaScript Libraries von Ikuru Kanuma
Locarise,reagent and JavaScript LibrariesLocarise,reagent and JavaScript Libraries
Locarise,reagent and JavaScript Libraries
Ikuru Kanuma479 views
Brian Hoke: WordCamp Toronto 2014 Presentation "Sass & WordPress" von bentleyhoke
Brian Hoke: WordCamp Toronto 2014 Presentation "Sass & WordPress"Brian Hoke: WordCamp Toronto 2014 Presentation "Sass & WordPress"
Brian Hoke: WordCamp Toronto 2014 Presentation "Sass & WordPress"
bentleyhoke604 views
Distributed caching for your next node.js project cf summit - 06-15-2017 von Viktor Gamov
Distributed caching for your next node.js project   cf summit - 06-15-2017Distributed caching for your next node.js project   cf summit - 06-15-2017
Distributed caching for your next node.js project cf summit - 06-15-2017
Viktor Gamov295 views

Similar a 3 ways-to-create-sprites-in-rails

Css sprite best practices von
Css sprite best practicesCss sprite best practices
Css sprite best practicesRichard Huang
3.1K views17 Folien
Css sprite_maker-1 von
Css  sprite_maker-1Css  sprite_maker-1
Css sprite_maker-1lokku
1.9K views26 Folien
Adobe MAX 2008: HTML/CSS + Fireworks von
Adobe MAX 2008: HTML/CSS + FireworksAdobe MAX 2008: HTML/CSS + Fireworks
Adobe MAX 2008: HTML/CSS + FireworksNathan Smith
2K views63 Folien
High Performance Webdesign von
High Performance WebdesignHigh Performance Webdesign
High Performance Webdesign拓樹 谷
3.9K views120 Folien
Make Your Animations Perform Well - JS Conf Budapest 2017 von
Make Your Animations Perform Well - JS Conf Budapest 2017 Make Your Animations Perform Well - JS Conf Budapest 2017
Make Your Animations Perform Well - JS Conf Budapest 2017 Anna Migas
736 views86 Folien
Death of a Themer von
Death of a ThemerDeath of a Themer
Death of a ThemerJames Panton
4.3K views90 Folien

Similar a 3 ways-to-create-sprites-in-rails(20)

Css sprite best practices von Richard Huang
Css sprite best practicesCss sprite best practices
Css sprite best practices
Richard Huang3.1K views
Css sprite_maker-1 von lokku
Css  sprite_maker-1Css  sprite_maker-1
Css sprite_maker-1
lokku1.9K views
Adobe MAX 2008: HTML/CSS + Fireworks von Nathan Smith
Adobe MAX 2008: HTML/CSS + FireworksAdobe MAX 2008: HTML/CSS + Fireworks
Adobe MAX 2008: HTML/CSS + Fireworks
Nathan Smith2K views
High Performance Webdesign von 拓樹 谷
High Performance WebdesignHigh Performance Webdesign
High Performance Webdesign
拓樹 谷3.9K views
Make Your Animations Perform Well - JS Conf Budapest 2017 von Anna Migas
Make Your Animations Perform Well - JS Conf Budapest 2017 Make Your Animations Perform Well - JS Conf Budapest 2017
Make Your Animations Perform Well - JS Conf Budapest 2017
Anna Migas736 views
Make your animations perform well - Anna Migas - Codemotion Rome 2017 von Codemotion
Make your animations perform well - Anna Migas - Codemotion Rome 2017Make your animations perform well - Anna Migas - Codemotion Rome 2017
Make your animations perform well - Anna Migas - Codemotion Rome 2017
Codemotion740 views
Font End Development + Automation with Django von Evan Reiser
Font End Development + Automation with DjangoFont End Development + Automation with Django
Font End Development + Automation with Django
Evan Reiser1.9K views
create-netflix-clone-06-client-ui_transcript.pdf von ShaiAlmog1
create-netflix-clone-06-client-ui_transcript.pdfcreate-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdf
ShaiAlmog1239 views
Make your animations perform well von Anna Migas
Make your animations perform wellMake your animations perform well
Make your animations perform well
Anna Migas131 views
CreateJSの概要 + Animate CC 2018の新機能 von Yasunobu Ikeda
CreateJSの概要 + Animate CC 2018の新機能CreateJSの概要 + Animate CC 2018の新機能
CreateJSの概要 + Animate CC 2018の新機能
Yasunobu Ikeda1.9K views
分层语义化模板实践 ---- 张克军 von 裕波 周
分层语义化模板实践 ---- 张克军分层语义化模板实践 ---- 张克军
分层语义化模板实践 ---- 张克军
裕波 周1.1K views
Keeping the frontend under control with Symfony and Webpack von Ignacio Martín
Keeping the frontend under control with Symfony and WebpackKeeping the frontend under control with Symfony and Webpack
Keeping the frontend under control with Symfony and Webpack
Ignacio Martín6.4K views
Progressive downloads and rendering (Stoyan Stefanov) von Ontico
Progressive downloads and rendering (Stoyan Stefanov)Progressive downloads and rendering (Stoyan Stefanov)
Progressive downloads and rendering (Stoyan Stefanov)
Ontico1.4K views

Último

How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ... von
How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...
How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...ShapeBlue
171 views28 Folien
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue von
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueCloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueShapeBlue
139 views15 Folien
"Surviving highload with Node.js", Andrii Shumada von
"Surviving highload with Node.js", Andrii Shumada "Surviving highload with Node.js", Andrii Shumada
"Surviving highload with Node.js", Andrii Shumada Fwdays
58 views29 Folien
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT von
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBITUpdates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBITShapeBlue
208 views8 Folien
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ... von
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...Jasper Oosterveld
35 views49 Folien
The Role of Patterns in the Era of Large Language Models von
The Role of Patterns in the Era of Large Language ModelsThe Role of Patterns in the Era of Large Language Models
The Role of Patterns in the Era of Large Language ModelsYunyao Li
91 views65 Folien

Último(20)

How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ... von ShapeBlue
How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...
How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...
ShapeBlue171 views
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue von ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueCloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
ShapeBlue139 views
"Surviving highload with Node.js", Andrii Shumada von Fwdays
"Surviving highload with Node.js", Andrii Shumada "Surviving highload with Node.js", Andrii Shumada
"Surviving highload with Node.js", Andrii Shumada
Fwdays58 views
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT von ShapeBlue
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBITUpdates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT
ShapeBlue208 views
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ... von Jasper Oosterveld
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
The Role of Patterns in the Era of Large Language Models von Yunyao Li
The Role of Patterns in the Era of Large Language ModelsThe Role of Patterns in the Era of Large Language Models
The Role of Patterns in the Era of Large Language Models
Yunyao Li91 views
LLMs in Production: Tooling, Process, and Team Structure von Aggregage
LLMs in Production: Tooling, Process, and Team StructureLLMs in Production: Tooling, Process, and Team Structure
LLMs in Production: Tooling, Process, and Team Structure
Aggregage57 views
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha... von ShapeBlue
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...
ShapeBlue183 views
"Node.js Development in 2024: trends and tools", Nikita Galkin von Fwdays
"Node.js Development in 2024: trends and tools", Nikita Galkin "Node.js Development in 2024: trends and tools", Nikita Galkin
"Node.js Development in 2024: trends and tools", Nikita Galkin
Fwdays33 views
Transcript: Redefining the book supply chain: A glimpse into the future - Tec... von BookNet Canada
Transcript: Redefining the book supply chain: A glimpse into the future - Tec...Transcript: Redefining the book supply chain: A glimpse into the future - Tec...
Transcript: Redefining the book supply chain: A glimpse into the future - Tec...
BookNet Canada41 views
Optimizing Communication to Optimize Human Behavior - LCBM von Yaman Kumar
Optimizing Communication to Optimize Human Behavior - LCBMOptimizing Communication to Optimize Human Behavior - LCBM
Optimizing Communication to Optimize Human Behavior - LCBM
Yaman Kumar38 views
Why and How CloudStack at weSystems - Stephan Bienek - weSystems von ShapeBlue
Why and How CloudStack at weSystems - Stephan Bienek - weSystemsWhy and How CloudStack at weSystems - Stephan Bienek - weSystems
Why and How CloudStack at weSystems - Stephan Bienek - weSystems
ShapeBlue247 views
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue von ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlueElevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
ShapeBlue224 views
Initiating and Advancing Your Strategic GIS Governance Strategy von Safe Software
Initiating and Advancing Your Strategic GIS Governance StrategyInitiating and Advancing Your Strategic GIS Governance Strategy
Initiating and Advancing Your Strategic GIS Governance Strategy
Safe Software184 views
Business Analyst Series 2023 - Week 4 Session 7 von DianaGray10
Business Analyst Series 2023 -  Week 4 Session 7Business Analyst Series 2023 -  Week 4 Session 7
Business Analyst Series 2023 - Week 4 Session 7
DianaGray10146 views
Webinar : Desperately Seeking Transformation - Part 2: Insights from leading... von The Digital Insurer
Webinar : Desperately Seeking Transformation - Part 2:  Insights from leading...Webinar : Desperately Seeking Transformation - Part 2:  Insights from leading...
Webinar : Desperately Seeking Transformation - Part 2: Insights from leading...
Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De... von Moses Kemibaro
Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De...Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De...
Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De...
Moses Kemibaro35 views
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And... von ShapeBlue
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...
ShapeBlue108 views
Live Demo Showcase: Unveiling Dell PowerFlex’s IaaS Capabilities with Apache ... von ShapeBlue
Live Demo Showcase: Unveiling Dell PowerFlex’s IaaS Capabilities with Apache ...Live Demo Showcase: Unveiling Dell PowerFlex’s IaaS Capabilities with Apache ...
Live Demo Showcase: Unveiling Dell PowerFlex’s IaaS Capabilities with Apache ...
ShapeBlue129 views

3 ways-to-create-sprites-in-rails

  • 1. 3 Ways to Create CSS Sprites With Rails
  • 3. A great way to save HTTP requests.
  • 4. In other words: Something that makes your website faster. awes om e!
  • 6. Rails 3.1 > Integrated Spriting CSS_Sprite > better <img> Lemonade > Full CSS sprites
  • 7. Finding Information http://www.drdobbs.com/blog/archives/2010/06/preparing_for_r.html
  • 9. A Piece of Code http://twitter.com/jsiarto/status/15861245321
  • 10. Finally! http://www.rubyinside.com/dhhs-railsconf-2010-keynote-video-a-justification-of-rails-3-0-3325.html
  • 11. Generation Sprites <%= sprite_css("icons") %> ★ Combines all images of a folder ★ Generates CSS
  • 12. Using Images <%= sprite_tag("icons/trash") %> ★ Adds a HTML tag with the class (I guess it works this way.)
  • 13. Questions ★ Is it possible to pack CSS files? ★ Why “icons/trash” if image_tag requires “icons/trash.png”? ★ When will it be available?
  • 14. Rails 3.1 > Integrated Spriting CSS_Sprite > better <img> Lemonade > Full CSS sprites
  • 16. Features ★ Creates sprite images ★ Creates classes for each file ★ Sass compatible ★ Rake Task for generation
  • 17. From Image to CCS images under css_sprite directory class name in css_sprite css twitter_icon.png .twitter_icon facebook_icon.png .facebook_icon hotmail-logo.png .hotmail-logo gmail-logo.png .gmail-logo icons/twitter_icon.png .icons .twitter_icon widget/icons/twitter_icon.png .widget .icons .twitter_icon twitter_icon_hover.png .twitter_icon:hover twitter-icon-hover.png .twitter-icon:hover logos_hover/gmail_logo.png .logos:hover .gmail_logo logos-hover/gmail-logo.png .logos:hover .gmail-logo … … full table at http://github.com/flyerhzm/css_sprite
  • 18. Built Sprites (1) rake css_sprite:build
  • 19. Built Sprites (2) rake css_sprite:start
  • 20. Pros ★ Easy for HTML developers ★ Easy if you’re handling <img> tag
  • 21. Cons ★ A lot of CSS generated (sizes, …) ★ Additional non-semantic tags ★ Additional classes ★ Positioned background images difficult ★ RMagick ★ Rake task
  • 22. Alternatives ★ http://github.com/gistinc/sprite based on css_sprite ★ http://github.com/sblackstone/auto_sprite image_tag extention + CSS classes ★ http://github.com/setepo/css-sprites image_tag extention + inline CSS
  • 23. Rails 3.1 > Integrated Spriting CSS_Sprite > better <img> Lemonade > Easy Sprites
  • 26. Simple Sprites .add { background: sprite-image("icons/pl.png"); } .remove { background: sprite-image("icons/rm.png"); } all icons by p.yusukekamiyamane.com (CC by 3.0)
  • 27. Output .add { background: url("icons.png"); } .remove { background: url("icons.png") 0 -16px; }
  • 28. Right Aligned .something { background: sprite-image("i/wide.png"); } a.next { background: yellow no-repeat sprite-image("i/n.png", 100%); padding-right: 20px; }
  • 29. Result .something { background: url("i.png"); } Example link a.next { background: yellow no-repeat url("i.png") 100% -20px; padding-right: 20px; }
  • 30. Empty Space .add { background: sprite-image("icons/pl.png"); } .remove { background: yellow no-repeat sprite-image("icons/rm.png"); padding: 20px; }
  • 31. Could be Better .add { background: url("icons.png"); } .remove { Example link background: url("icons.png") 0 -16px; padding: 20px; }
  • 32. Empty Space .add { background: sprite-image("icons/pl.png"); } .remove { background: yellow no-repeat sprite-image("icons/rm.png", 0, 0, 20px); padding: 20px; }
  • 33. Just Perfect .add { background: url("icons.png"); } .remove { Example link background: url("icons.png") 0 -36px; padding: 20px; }
  • 34. Sprite Generation ★ Sprite image named by directory: “icons/*.png” > “icons.png” ★ Background position added only if needed ★ Add “no-repeat” by yourself: background: sprite-image("…") no-repeat;
  • 37. last name first name nico@hagenburger.net e-mail twitter blog