Results 1 to 7 of 7
-
15th Jun 2010, 11:14 AM #1OPლ(ಠ益ಠლ)Website's:
extremecoderz.com[html/css] Mouse Hover Button using Sprites
In this small example, i will be showing you how to create a button with a mouseover effect. This means when you position your mouse over the button, the image will change.
In this example we will be using something called a sprite; an image containing both the regular and mouse-over image.
So.
Let me explain a basic fundamental of CSS before i begin. It is extremely important you understand this if you wish to create valid code, and i see this so many times its just not funny anymore.
There are many ways to "reference" CSS, but there are 2 very common ways; A "class" identifier or an "ID" identifier. A class can be re-used as many times as you like. An ID cannot. It is a unique identifier. You cannot re-use ID's. Doing so will not validate.
Ok. So.
Here is the image we will be using; a very simple example, just to explain the fundamentals of using "hover":
Note how both the regular and hover images are housed in the same image. So why do it like this? For 2 key reasons:
1) Reduced HTTP requests. Every time you request a file, it gives your server more work to do. As a coder, its your job to ensure that you do this as little possible. A bad coder could code a skin with maybe 80 HTTP requests for the various images. A good coder could have maybe reduced 75% of those requests.
2) Seamless, flickerless buttons. If we were not using a sprite, the "mouseover" image would not be "downloaded" until we request it (putting your mouse over the button). On a slow connection the delay is clearly visible. We dont want that. We know better
So. The code for this is very simple and understandable, but i shall explain each part to ensure everything is understood:
First we shall start with the CSS:
Code:#myButton { background: url(images/buttonSprite.png) no-repeat; height: 50px; width: 200px; } #myButton:hover { background-position: 0px -51px }
The #myButton ID simply states the location of the image, followed by the height and width of the button, NOT the entire image(sprite).
Secondly we see #myButton:hover - This CSS will be called when the user hovers their mouse over the button. Here we see only one property; background-position. We are only going to modify the vertical positioning of the image. The first number (0px) is the horizontal position. We want that to remain 0px. The second number is the vertical position. We want that to change when the user hovers their cursor over the button. And we want it to move up 51px to display the second image in the sprite (the lower image).
Ok. So. Now for the HTML. We did all the hard work in the CSS, so now we can reap the rewards:
Code:<div ID="myButton"></div>
Live Example: http://coding.extremecoderz.com/simpleMouseOver.htmljayfella Reviewed by jayfella on . [html/css] Mouse Hover Button using Sprites In this small example, i will be showing you how to create a button with a mouseover effect. This means when you position your mouse over the button, the image will change. In this example we will be using something called a sprite; an image containing both the regular and mouse-over image. So. Let me explain a basic fundamental of CSS before i begin. It is extremely important you understand this if you wish to create valid code, and i see this so many times its just not funny anymore. Rating: 5
-
15th Jun 2010, 11:18 AM #2Member
Nice tutorial mate this will be known as the first useful thread of the Development Area.
A life spent making mistakes is not only more honorable, but more useful than a life spent doing nothing. ? George Bernard Shaw
?
Designer. Check my designs here.
-
15th Jun 2010, 11:18 AM #3Member
Nice Info .. Brother Thanks
(.*??)
.?.?.?.?*??) .........?.?*?)........
(?.??BuzzScene.(?.?*??)
............(?.??.....................(?.??*?`)
-
15th Jun 2010, 11:19 AM #4Teh GFX Whore! ^.^
live example link ain't working
-
15th Jun 2010, 11:20 AM #5OPლ(ಠ益ಠლ)Website's:
extremecoderz.comlive example works perfect m8 - its cross-platform valid.
-
15th Jun 2010, 11:21 AM #6MemberWebsite's:
LulzIMG.com chtbx.com RapidPremium.Net ReleaseLeech.com RLSLeech.com NinjaRobotPirateZombieNazi.comKickass tutorial Jay. Keep 'em comin'!
jayfella is in your box. Eating your cookiez.
-
15th Jun 2010, 11:21 AM #7Teh GFX Whore! ^.^
now its working.. i mean the url wasn't working..leave it anyways..good work
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
Social Network Icons in form of CSS Sprites for websites
By flanker in forum Web Development AreaReplies: 1Last Post: 15th Jun 2012, 06:19 AM -
[Hiring] Combine images using CSS sprites
By chakravarti in forum Completed TransactionsReplies: 8Last Post: 14th Apr 2011, 05:05 AM -
CSS Sprites Help
By BlaZe in forum Web Development AreaReplies: 8Last Post: 16th Feb 2011, 08:45 AM -
Html Button help wp
By devilzkrazy in forum Technical Help Desk SupportReplies: 3Last Post: 4th May 2010, 01:36 PM -
CSS - Sprites (Web 3.0) Tutorial
By litewarez in forum Tutorials and GuidesReplies: 14Last Post: 29th May 2009, 01:01 AM
themaPoster - post to forums and...
Version 5.22 released. Open older version (or...