Activity Stream
48,167 MEMBERS
6953 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Results 1 to 7 of 7
  1.     
    #1
    ლ(ಠ益ಠლ)
    Website's:
    extremecoderz.com

    Default [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 }
    Ok. Firstly, the # means it is a unique ID, not a class. If we were going to re-use this code, we could simply exchange the # for a full-stop.
    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>
    Simple eh

    Live Example: http://coding.extremecoderz.com/simpleMouseOver.html
    jayfella 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

  2.   Sponsored Links

  3.     
    #2
    Member
    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.

  4.     
    #3
    Member
    Nice Info .. Brother Thanks
    (.*??)
    .?.?.?.?*??) .........?.?*?)........
    (?.??BuzzScene.(?.?*??)
    ............(?.??.....................(?.??*?`)

  5.     
    #4
    Teh GFX Whore! ^.^
    live example link ain't working


    I joined KWWHunction before it was cool!
    My "AWESOME" Graphic designing Service


  6.     
    #5
    ლ(ಠ益ಠლ)
    Website's:
    extremecoderz.com
    live example works perfect m8 - its cross-platform valid.

  7.     
    #6
    Member
    Website's:
    LulzIMG.com chtbx.com RapidPremium.Net ReleaseLeech.com RLSLeech.com NinjaRobotPirateZombieNazi.com
    Kickass tutorial Jay. Keep 'em comin'!

    jayfella is in your box. Eating your cookiez.

  8.     
    #7
    Teh GFX Whore! ^.^
    now its working.. i mean the url wasn't working..leave it anyways..good work


    I joined KWWHunction before it was cool!
    My "AWESOME" Graphic designing Service


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Social Network Icons in form of CSS Sprites for websites
    By flanker in forum Web Development Area
    Replies: 1
    Last Post: 15th Jun 2012, 06:19 AM
  2. [Hiring] Combine images using CSS sprites
    By chakravarti in forum Completed Transactions
    Replies: 8
    Last Post: 14th Apr 2011, 05:05 AM
  3. CSS Sprites Help
    By BlaZe in forum Web Development Area
    Replies: 8
    Last Post: 16th Feb 2011, 08:45 AM
  4. Html Button help wp
    By devilzkrazy in forum Technical Help Desk Support
    Replies: 3
    Last Post: 4th May 2010, 01:36 PM
  5. CSS - Sprites (Web 3.0) Tutorial
    By litewarez in forum Tutorials and Guides
    Replies: 14
    Last Post: 29th May 2009, 01:01 AM

Tags for this Thread

BE SOCIAL