Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,217,681 members, 8,035,104 topics. Date: Sunday, 22 December 2024 at 11:10 PM

How To: Create A Simple Hover Button With Html And Css - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / How To: Create A Simple Hover Button With Html And Css (6101 Views)

Free New E-book On HTML And CSS / What Can One Do With Html / Help With Html/php Form Preview (2) (3) (4)

(1) (Reply) (Go Down)

How To: Create A Simple Hover Button With Html And Css by DualCore1: 5:33pm On Jan 25, 2012
The whole idea it to take advantage of CSS's "hover" and background positioning.

Steps
1. Create the button, duplicate the button and place it above the first one created and darken it or add any other effect you want to add to it as that will be the image that will be show on mouseover.

2. Save the button is a convinient place.

3. Go over and write the html and CSS as shown below.

<style>
#login_button {background:url(login_button.jpg) no-repeat bottom; height:56px; width:144px;display:block;}
#login_button:hover{background:url(login_button.jpg) no-repeat top; height:56px; width:144px;display:block;}
</style>

<a href="#" id="login_button"></a>



A demo of the exact code can be seen here:
http://sawyerrken.net/demo/simple_hover.html

The login button image used is attached.

Re: How To: Create A Simple Hover Button With Html And Css by yawatide(f): 5:53pm On Jan 25, 2012
Another (perhaps better) way to skin the cat:

Rather than import/use 2 images, you could save a few bytes by using a sprite and positioning it appropriately when you hover by using CSS's background-position property wink
Re: How To: Create A Simple Hover Button With Html And Css by Nobody: 6:25pm On Jan 25, 2012
^^^Or rather a coke effect. Personalmente, i prefer it without the sprite jare.
Re: How To: Create A Simple Hover Button With Html And Css by Nobody: 6:26pm On Jan 25, 2012
<style>
#login_button {background:url(login_button.jpg) no-repeat bottom; height:56px; width:144px;}
#login_button:hover{background:url(login_button.jpg) no-repeat top;}
</style>

<a href="#" id="login_button"></a>
A short-hand version is this. Should do the same work exactamente.
Re: How To: Create A Simple Hover Button With Html And Css by DualCore1: 7:15pm On Jan 25, 2012
yawa-ti-de:

Another (perhaps better) way to skin the cat:

Rather than import/use 2 images, you could save a few bytes by using a sprite and positioning it appropriately when you hover by using CSS's background-position property wink

The example I gave above uses one image, not 2.

I have bolded some part of the code to show the positioning.
Re: How To: Create A Simple Hover Button With Html And Css by Nobody: 7:17pm On Jan 25, 2012
I get your point, it is good actually. Nice contribution.
Re: How To: Create A Simple Hover Button With Html And Css by DualCore1: 7:19pm On Jan 25, 2012
[i]Fanta[/i]stic
Re: How To: Create A Simple Hover Button With Html And Css by yawatide(f): 9:24pm On Jan 25, 2012
My bad. Didn't see the bolded portions initially. Besides, I should have taken a cue from the image that you attached, which is actually one image.

Carry go, he he tongue

(1) (Reply)

How Lucrative Is Selling Data Bundle Online / How Do I Build An Intranet / Verified Paypal Accs For Sell @ N5000

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 10
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.