SlideShare a Scribd company logo
1 of 2
Download to read offline
Tutorio.com
Subcategories: View All Announcements. Clientside. Flash. Marketing-SEO. Photoshop. Serverside.
In this tutorial you will learn how to transform an ordinary link into a button with image rollovers using
nothing but css.
Introduction
Example: Rollover Buttons with pure CSS.
View Rollover Example
(*edit* actually I found out that the buttons do 'sometimes' flicker in IE )
Normally image rollovers involve replacing one image with another, when the mouse is moved over the button. This causes a problem because the new image
has need to be loaded when the mouse is moved over the button. The delay between the time the mouse is moved over the button and when the image is loaded
results in a flicker.
The traditional method of solving this is to preload all the images using bulky javascript.
A better solution is available through css, it involes putting all three states of a button (normal, hover, hit) on one image, and then simply moving the image
around
(x)HTML Markup
Create a menu using the following HTML
<div class="rollover">
<a href="#">Item 1</a>
<a href="#">Item 2</a>
<a href="#">Item 3</a>
<a href="#">Tutorio</a>
</div>
The HTML markup is very simple, its just a bunch ordinary links inside a div tag with the class rollover.
Creating the image
The first step is to creating a button is to create a background graphic for the button in an image editor such as photoshop.
Divide the image up into three equal sections, one for each state of the button.
Normal (what the button looks like normally )
Hover (this will be used when the image is rolled over.)
Hit (this will be used when the mouse is clicked.)
The CSS
At this point all you have is a bunch of links and an image, what really ties this together is CSS 2
.rollover a {
display:block;
width: 90px;
padding:10px 10px 10px 7px;
font: bold 13px sans-serif;;
color:#333;
background: url("rollover-image.gif") 0 0 no-repeat;
text-decoration: none;
}
.rollover a:hover {
background-position: 0 -35px;
color: #049;
}
.rollover a:active {
background-position: 0 -70px;
color:#fff;
}
Pure CSS Image Rollovers
jumpchart.com Ads by Google
Page 1 of 2Pure CSS Image Rollovers
8/16/2010http://www.tutorio.com/tutorial/pure-css-image-rollovers
The important thing to notice here is image that you created is used as a background for the links. The background is then positioned on a:hover (on rollover), and
on a:active (on click)
My image was 105 pixel high and divided up into blocks of 35px each. So the background is positioned at -35px on rollover (a:hover) to move it up by 35 pixels. I
change the background position, on a:active to move it up by -70px so that only the bottom part of the image is seen
Also notice the padding values, and the width these will vary from image to image
Tip: If you want to create a horizontal navigation instead of a vertical one have a look at this thread.
Rating(556) + -
Chaotic Fire Flames
Javascript Bubbles
XMPlay Icon
Making Fit Different Screen Resolutions
Using Photoshop Move Tool: Complete Reference
Tutorio.com. Privacy Policy, Contact
More Tutorials
Page 2 of 2Pure CSS Image Rollovers
8/16/2010http://www.tutorio.com/tutorial/pure-css-image-rollovers

More Related Content

Similar to Pure css-image-rollovers

Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4Erin M. Kidwell
 
Mobile Monday Presentation: Responsive Web Design
Mobile Monday Presentation: Responsive Web DesignMobile Monday Presentation: Responsive Web Design
Mobile Monday Presentation: Responsive Web DesignCantina
 
Html 5 and CSS - Image Element
Html 5 and CSS - Image ElementHtml 5 and CSS - Image Element
Html 5 and CSS - Image ElementKempy7000
 
Project 2 presentation wen liu
Project 2 presentation wen liuProject 2 presentation wen liu
Project 2 presentation wen liumaranzasliu
 
Building a Website from Planning to Photoshop Mockup to HTML/CSS
Building a Website from Planning to Photoshop Mockup to HTML/CSSBuilding a Website from Planning to Photoshop Mockup to HTML/CSS
Building a Website from Planning to Photoshop Mockup to HTML/CSShstryk
 
Need help with this project. I am confused what i have to do in this.pdf
Need help with this project. I am confused what i have to do in this.pdfNeed help with this project. I am confused what i have to do in this.pdf
Need help with this project. I am confused what i have to do in this.pdfamazonedistributors
 
Practical tipsmakemobilefaster oscon2016
Practical tipsmakemobilefaster oscon2016Practical tipsmakemobilefaster oscon2016
Practical tipsmakemobilefaster oscon2016Doris Chen
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAAiman Hud
 
Responsive Web Design: Clever Tips and Techniques
Responsive Web Design: Clever Tips and TechniquesResponsive Web Design: Clever Tips and Techniques
Responsive Web Design: Clever Tips and TechniquesVitaly Friedman
 
Blog HTML example for IML 295
Blog HTML example for IML 295Blog HTML example for IML 295
Blog HTML example for IML 295Evan Hughes
 
Responsive Web Design tips and tricks.
Responsive Web Design tips and tricks.Responsive Web Design tips and tricks.
Responsive Web Design tips and tricks.GaziAhsan
 
PreDevCampSF - CSS3 Tricks
PreDevCampSF - CSS3 TricksPreDevCampSF - CSS3 Tricks
PreDevCampSF - CSS3 Tricksincidentist
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAAiman Hud
 
Tailwind Animation: How to Make Eye-Catching Websites
Tailwind Animation: How to Make Eye-Catching WebsitesTailwind Animation: How to Make Eye-Catching Websites
Tailwind Animation: How to Make Eye-Catching WebsitesRonDosh
 
CSS-in-JS: unexpected lessons for Drupal component design
CSS-in-JS: unexpected lessons for Drupal component designCSS-in-JS: unexpected lessons for Drupal component design
CSS-in-JS: unexpected lessons for Drupal component designJohn Albin Wilkins
 

Similar to Pure css-image-rollovers (20)

Css rollover
Css rolloverCss rollover
Css rollover
 
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
 
Rollov
RollovRollov
Rollov
 
Mobile Monday Presentation: Responsive Web Design
Mobile Monday Presentation: Responsive Web DesignMobile Monday Presentation: Responsive Web Design
Mobile Monday Presentation: Responsive Web Design
 
Html 5 and CSS - Image Element
Html 5 and CSS - Image ElementHtml 5 and CSS - Image Element
Html 5 and CSS - Image Element
 
Project 2 presentation wen liu
Project 2 presentation wen liuProject 2 presentation wen liu
Project 2 presentation wen liu
 
Building a Website from Planning to Photoshop Mockup to HTML/CSS
Building a Website from Planning to Photoshop Mockup to HTML/CSSBuilding a Website from Planning to Photoshop Mockup to HTML/CSS
Building a Website from Planning to Photoshop Mockup to HTML/CSS
 
Html5
Html5Html5
Html5
 
Need help with this project. I am confused what i have to do in this.pdf
Need help with this project. I am confused what i have to do in this.pdfNeed help with this project. I am confused what i have to do in this.pdf
Need help with this project. I am confused what i have to do in this.pdf
 
Practical tipsmakemobilefaster oscon2016
Practical tipsmakemobilefaster oscon2016Practical tipsmakemobilefaster oscon2016
Practical tipsmakemobilefaster oscon2016
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
Responsive Web Design: Clever Tips and Techniques
Responsive Web Design: Clever Tips and TechniquesResponsive Web Design: Clever Tips and Techniques
Responsive Web Design: Clever Tips and Techniques
 
Blog HTML example for IML 295
Blog HTML example for IML 295Blog HTML example for IML 295
Blog HTML example for IML 295
 
Rwd slidedeck
Rwd slidedeckRwd slidedeck
Rwd slidedeck
 
Responsive Web Design tips and tricks.
Responsive Web Design tips and tricks.Responsive Web Design tips and tricks.
Responsive Web Design tips and tricks.
 
PreDevCampSF - CSS3 Tricks
PreDevCampSF - CSS3 TricksPreDevCampSF - CSS3 Tricks
PreDevCampSF - CSS3 Tricks
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
FrontinFortaleza 2015
FrontinFortaleza 2015FrontinFortaleza 2015
FrontinFortaleza 2015
 
Tailwind Animation: How to Make Eye-Catching Websites
Tailwind Animation: How to Make Eye-Catching WebsitesTailwind Animation: How to Make Eye-Catching Websites
Tailwind Animation: How to Make Eye-Catching Websites
 
CSS-in-JS: unexpected lessons for Drupal component design
CSS-in-JS: unexpected lessons for Drupal component designCSS-in-JS: unexpected lessons for Drupal component design
CSS-in-JS: unexpected lessons for Drupal component design
 

More from Daniel Downs

Developing a mobile application curriculum which empowers authentic
Developing a mobile application curriculum which empowers authenticDeveloping a mobile application curriculum which empowers authentic
Developing a mobile application curriculum which empowers authenticDaniel Downs
 
Module11: Creating A External Style Sheet and Creating A Gallery
Module11: Creating A External Style Sheet and Creating A GalleryModule11: Creating A External Style Sheet and Creating A Gallery
Module11: Creating A External Style Sheet and Creating A GalleryDaniel Downs
 
Seo continued page 2
Seo continued page 2Seo continued page 2
Seo continued page 2Daniel Downs
 
Module 10search engine optimization
Module 10search engine optimizationModule 10search engine optimization
Module 10search engine optimizationDaniel Downs
 
Ipad quick-reference-2
Ipad quick-reference-2Ipad quick-reference-2
Ipad quick-reference-2Daniel Downs
 
Index of jquery template 2 Minuteman Summer Web Dev.
Index of jquery template 2 Minuteman Summer Web Dev.Index of jquery template 2 Minuteman Summer Web Dev.
Index of jquery template 2 Minuteman Summer Web Dev.Daniel Downs
 
Jquery template 1 3 pages
Jquery template 1 3 pagesJquery template 1 3 pages
Jquery template 1 3 pagesDaniel Downs
 
Module6 htmlcss helpfulcodeandwebsites
Module6 htmlcss helpfulcodeandwebsitesModule6 htmlcss helpfulcodeandwebsites
Module6 htmlcss helpfulcodeandwebsitesDaniel Downs
 
Module 4 Minuteman Lexington Web Design Daniel Downs
Module 4 Minuteman Lexington Web Design Daniel DownsModule 4 Minuteman Lexington Web Design Daniel Downs
Module 4 Minuteman Lexington Web Design Daniel DownsDaniel Downs
 
Module 3 Progress Codes Web Design Daniel Downs Minuteman Lexington Ma
Module 3 Progress Codes Web Design Daniel Downs Minuteman Lexington MaModule 3 Progress Codes Web Design Daniel Downs Minuteman Lexington Ma
Module 3 Progress Codes Web Design Daniel Downs Minuteman Lexington MaDaniel Downs
 
Module 2 lexington minuteman web development basic layout template
Module 2  lexington minuteman web development basic layout templateModule 2  lexington minuteman web development basic layout template
Module 2 lexington minuteman web development basic layout templateDaniel Downs
 
Module 1 Web design & Development Lexington Minuteman
Module 1 Web design & Development Lexington MinutemanModule 1 Web design & Development Lexington Minuteman
Module 1 Web design & Development Lexington MinutemanDaniel Downs
 
App research project
App research projectApp research project
App research projectDaniel Downs
 
Daniel Downs: Student Experiences In A Project Based Learning Technology Curr...
Daniel Downs: Student Experiences In A Project Based Learning Technology Curr...Daniel Downs: Student Experiences In A Project Based Learning Technology Curr...
Daniel Downs: Student Experiences In A Project Based Learning Technology Curr...Daniel Downs
 
Blogger custom domain on go daddy blogger widgets
Blogger custom domain on go daddy   blogger widgetsBlogger custom domain on go daddy   blogger widgets
Blogger custom domain on go daddy blogger widgetsDaniel Downs
 
Outline for action research prospectus
Outline for action research prospectusOutline for action research prospectus
Outline for action research prospectusDaniel Downs
 
You have decided to go off on your own as a freelance webdesigner
You have decided to go off on your own as a freelance webdesignerYou have decided to go off on your own as a freelance webdesigner
You have decided to go off on your own as a freelance webdesignerDaniel Downs
 
Making a basicappinflash (1)
Making a basicappinflash (1)Making a basicappinflash (1)
Making a basicappinflash (1)Daniel Downs
 
Daniel Downs Technology Portfolio Final May 2013 final (1)
Daniel Downs Technology Portfolio Final May 2013 final (1)Daniel Downs Technology Portfolio Final May 2013 final (1)
Daniel Downs Technology Portfolio Final May 2013 final (1)Daniel Downs
 
Web design 1& 2 lesson outline
Web design 1& 2 lesson outlineWeb design 1& 2 lesson outline
Web design 1& 2 lesson outlineDaniel Downs
 

More from Daniel Downs (20)

Developing a mobile application curriculum which empowers authentic
Developing a mobile application curriculum which empowers authenticDeveloping a mobile application curriculum which empowers authentic
Developing a mobile application curriculum which empowers authentic
 
Module11: Creating A External Style Sheet and Creating A Gallery
Module11: Creating A External Style Sheet and Creating A GalleryModule11: Creating A External Style Sheet and Creating A Gallery
Module11: Creating A External Style Sheet and Creating A Gallery
 
Seo continued page 2
Seo continued page 2Seo continued page 2
Seo continued page 2
 
Module 10search engine optimization
Module 10search engine optimizationModule 10search engine optimization
Module 10search engine optimization
 
Ipad quick-reference-2
Ipad quick-reference-2Ipad quick-reference-2
Ipad quick-reference-2
 
Index of jquery template 2 Minuteman Summer Web Dev.
Index of jquery template 2 Minuteman Summer Web Dev.Index of jquery template 2 Minuteman Summer Web Dev.
Index of jquery template 2 Minuteman Summer Web Dev.
 
Jquery template 1 3 pages
Jquery template 1 3 pagesJquery template 1 3 pages
Jquery template 1 3 pages
 
Module6 htmlcss helpfulcodeandwebsites
Module6 htmlcss helpfulcodeandwebsitesModule6 htmlcss helpfulcodeandwebsites
Module6 htmlcss helpfulcodeandwebsites
 
Module 4 Minuteman Lexington Web Design Daniel Downs
Module 4 Minuteman Lexington Web Design Daniel DownsModule 4 Minuteman Lexington Web Design Daniel Downs
Module 4 Minuteman Lexington Web Design Daniel Downs
 
Module 3 Progress Codes Web Design Daniel Downs Minuteman Lexington Ma
Module 3 Progress Codes Web Design Daniel Downs Minuteman Lexington MaModule 3 Progress Codes Web Design Daniel Downs Minuteman Lexington Ma
Module 3 Progress Codes Web Design Daniel Downs Minuteman Lexington Ma
 
Module 2 lexington minuteman web development basic layout template
Module 2  lexington minuteman web development basic layout templateModule 2  lexington minuteman web development basic layout template
Module 2 lexington minuteman web development basic layout template
 
Module 1 Web design & Development Lexington Minuteman
Module 1 Web design & Development Lexington MinutemanModule 1 Web design & Development Lexington Minuteman
Module 1 Web design & Development Lexington Minuteman
 
App research project
App research projectApp research project
App research project
 
Daniel Downs: Student Experiences In A Project Based Learning Technology Curr...
Daniel Downs: Student Experiences In A Project Based Learning Technology Curr...Daniel Downs: Student Experiences In A Project Based Learning Technology Curr...
Daniel Downs: Student Experiences In A Project Based Learning Technology Curr...
 
Blogger custom domain on go daddy blogger widgets
Blogger custom domain on go daddy   blogger widgetsBlogger custom domain on go daddy   blogger widgets
Blogger custom domain on go daddy blogger widgets
 
Outline for action research prospectus
Outline for action research prospectusOutline for action research prospectus
Outline for action research prospectus
 
You have decided to go off on your own as a freelance webdesigner
You have decided to go off on your own as a freelance webdesignerYou have decided to go off on your own as a freelance webdesigner
You have decided to go off on your own as a freelance webdesigner
 
Making a basicappinflash (1)
Making a basicappinflash (1)Making a basicappinflash (1)
Making a basicappinflash (1)
 
Daniel Downs Technology Portfolio Final May 2013 final (1)
Daniel Downs Technology Portfolio Final May 2013 final (1)Daniel Downs Technology Portfolio Final May 2013 final (1)
Daniel Downs Technology Portfolio Final May 2013 final (1)
 
Web design 1& 2 lesson outline
Web design 1& 2 lesson outlineWeb design 1& 2 lesson outline
Web design 1& 2 lesson outline
 

Pure css-image-rollovers

  • 1. Tutorio.com Subcategories: View All Announcements. Clientside. Flash. Marketing-SEO. Photoshop. Serverside. In this tutorial you will learn how to transform an ordinary link into a button with image rollovers using nothing but css. Introduction Example: Rollover Buttons with pure CSS. View Rollover Example (*edit* actually I found out that the buttons do 'sometimes' flicker in IE ) Normally image rollovers involve replacing one image with another, when the mouse is moved over the button. This causes a problem because the new image has need to be loaded when the mouse is moved over the button. The delay between the time the mouse is moved over the button and when the image is loaded results in a flicker. The traditional method of solving this is to preload all the images using bulky javascript. A better solution is available through css, it involes putting all three states of a button (normal, hover, hit) on one image, and then simply moving the image around (x)HTML Markup Create a menu using the following HTML <div class="rollover"> <a href="#">Item 1</a> <a href="#">Item 2</a> <a href="#">Item 3</a> <a href="#">Tutorio</a> </div> The HTML markup is very simple, its just a bunch ordinary links inside a div tag with the class rollover. Creating the image The first step is to creating a button is to create a background graphic for the button in an image editor such as photoshop. Divide the image up into three equal sections, one for each state of the button. Normal (what the button looks like normally ) Hover (this will be used when the image is rolled over.) Hit (this will be used when the mouse is clicked.) The CSS At this point all you have is a bunch of links and an image, what really ties this together is CSS 2 .rollover a { display:block; width: 90px; padding:10px 10px 10px 7px; font: bold 13px sans-serif;; color:#333; background: url("rollover-image.gif") 0 0 no-repeat; text-decoration: none; } .rollover a:hover { background-position: 0 -35px; color: #049; } .rollover a:active { background-position: 0 -70px; color:#fff; } Pure CSS Image Rollovers jumpchart.com Ads by Google Page 1 of 2Pure CSS Image Rollovers 8/16/2010http://www.tutorio.com/tutorial/pure-css-image-rollovers
  • 2. The important thing to notice here is image that you created is used as a background for the links. The background is then positioned on a:hover (on rollover), and on a:active (on click) My image was 105 pixel high and divided up into blocks of 35px each. So the background is positioned at -35px on rollover (a:hover) to move it up by 35 pixels. I change the background position, on a:active to move it up by -70px so that only the bottom part of the image is seen Also notice the padding values, and the width these will vary from image to image Tip: If you want to create a horizontal navigation instead of a vertical one have a look at this thread. Rating(556) + - Chaotic Fire Flames Javascript Bubbles XMPlay Icon Making Fit Different Screen Resolutions Using Photoshop Move Tool: Complete Reference Tutorio.com. Privacy Policy, Contact More Tutorials Page 2 of 2Pure CSS Image Rollovers 8/16/2010http://www.tutorio.com/tutorial/pure-css-image-rollovers