|
|
|
| Web Hosting Guide |
Creating Rollover Images With Css, Eliminate the need for Javascript |
Aug 31 2005, 01:18 AM
Post
#1
|
|
|
Advanced Member Group: Members Posts: 102 Joined: 21-August 05 Member No.: 8,003 |
I have seen it reported that 10% of Internet users have Javascript disabled. Whether for security concerns or to curtail annoyances like pop-up windows, it seriously limits your ability, as a web designer, to mold your website into something creative and novel.
This is where CSS rollovers come in. You know that effect you get when you roll the cursor over an image, and then the image changes? Traditionally, that effect has been accomplished by using Javascript to swap out images. I present here my own index page which has been made only with CSS and html. If you are unfamiliar with CSS, you may find this tutorial difficult to follow (and maybe even if you are familiar with it!). If you look at the page, you will probably assume that I used 8 images. But in actuality, I used only this one image: ![]() Let me explain. I placed an unordered list in the center of the page and specified the background-image property to point to the image I just showed you. Ostensibly, you could use any element that takes a class or id, rather than just a list, but the ul lends itself to this example. Importantly, I set the height of the ul block to cut off the bottom half of the background image. Here are my class specifications for the unordered list: CODE .circumcellion { [tab][/tab]background-image: url(circumcellion.gif); [tab][/tab]height: 176px; [tab][/tab]width: 755px; [tab][/tab]padding: 0; [tab][/tab]margin: 0; [tab][/tab]position: relative; [tab][/tab]} [tab][/tab] .circumcellion a { [tab][/tab]display: block; [tab][/tab]} .circumcellion li { [tab][/tab]list-style: none; position: absolute; [tab][/tab]} All of the list items within the unordered list are made into links and given their own class. Using CSS, I specify the positions and sizes of the list items and their links, respectively, like so: CODE .journal {left: 0px; top: 0px;} .trip {left: 180px; top: 46px;} .money {left: 467px; top: 16px;} .contact {left: 687px; top: 16px;} .journal a {width: 123px; height: 166px;} .trip a {width: 238px; height: 86px;} .money a {width: 163px; height: 149px;} .contact a {width: 67px; height: 151px;} As you may be aware, the CSS pseudo-class a:hover allows you to change attributes of a link when the cursor rolls over it. To add the rollover effect, I just have to call another instance of the same image. Using a:hover, you can pop up a background-image for the list item. So essentially, we are looking at a list item's background image in front of the list's background image. Understand? The following code tells the browser to use the image as a background and specifies how many pixels up and left to shift the image: CODE .journal a:hover {background: url(circumcellion.gif) 0px -176px no-repeat;} .trip a:hover {background: url(circumcellion.gif) -180px -222px no-repeat;} .money a:hover {background: url(circumcellion.gif) -467px -192px no-repeat;} .contact a:hover {background: url(circumcellion.gif) -687px -192px no-repeat;} And that's basically it. If I explained anything poorly, just ask for clarification. This is a complicated subject, and difficult to explain, so I would not be surprised if I left out something important. You can also look at my source code from the link above. Also, I want to give credit to powderseekers.com, whose code I intently studied to figure this whole thing out, and thanks to the Trap17 member who pointed out that CSS could be used thusly. |
|
|
|
![]() |
Replies
(1 - 9)
Sep 6 2005, 02:13 AM
Post
#2
|
|
|
Newbie [ Level 2 ] Group: Members Posts: 26 Joined: 4-September 05 Member No.: 8,302 |
I think I caught all of that. That's some really nifty stuff. I've been using CSS for about a year now and had no idea you could do that.
I had tried to learn JavaScript, but dropped it after about a week because I didn't have time then. I had no idea that 10% of internet users have JavaScript turned off, that does kind of limit things. Well done, and the site and member that helped are great as well. |
|
|
|
Dec 20 2005, 06:48 AM
Post
#3
|
|
|
Newbie [ Level 2 ] Group: Members Posts: 22 Joined: 20-December 05 From: New Delhi, India Member No.: 10,202 myCENTs:84.68 |
That is a nice good tutorial!
These days I am learning Css..so I didnt understand the code much but I am trying hard to learn CSS and I am sure this can come handy in designing good websites. Well, Thanks for this nice tutorial..it is a great effect and good way of displaying your website. |
|
|
|
Dec 20 2005, 09:29 AM
Post
#4
|
|
|
Veteran Nut Group: Members Posts: 527 Joined: 4-October 05 From: UK Member No.: 8,895 |
I have recently used CSS rollover images (in list style) to achieve a similar effect.
However, if you want to use more advanced things like onMouseDown images, then you're going to have to use JavaScript. |
|
|
|
Jan 6 2006, 07:51 AM
Post
#5
|
|
|
Advanced Member Group: Members Posts: 196 Joined: 15-November 05 From: Inland from the Left Coast of Canada Member No.: 9,627 myCENTs:43.09 |
Yes, I have seen similar coding using a two picture image for each button.
I have not seen it done this way with the 8 part image, though. Interesting approach. Good job on the tutorial. |
|
|
|
Jan 6 2006, 01:02 PM
Post
#6
|
|
|
the Q Group: [HOSTED] Posts: 1,314 Joined: 13-July 05 From: Lithuania, Vilnius Member No.: 7,059 myCENTs:14.53 |
This is really great, I wanted to make this effect with css myself, but had some problems, so I stayed with the javascript, but there is another issue, the browsers with no css support or people who has it turned off for some reason also is a headache for web designers, there are browsers with no css support, but with some kind of javascript support.
|
|
|
|
Feb 3 2006, 07:02 PM
Post
#7
|
|
|
Member [ Level 2 ] Group: Members Posts: 72 Joined: 3-February 06 From: UK Member No.: 11,052 |
QUOTE(Quatrux @ Jan 6 2006, 02:02 PM) there are browsers with no css support, but with some kind of javascript support. [right][snapback]66153[/snapback][/right] CSS is used alot around the web.... I would think that the majority of people have a browser that enables CSS (correct me if I'm wrong). Could you use both? In case one of them would be disables/non supported in the browser? |
|
|
|
Feb 13 2006, 01:31 AM
Post
#8
|
|
|
Advanced Member ![]() ![]() ![]() ![]() ![]() ![]() Group: Validating Posts: 111 Joined: 28-January 06 Member No.: 10,917 |
QUOTE(clagnol @ Aug 31 2005, 07:48 AM) [snapback]51147[/snapback] I have seen it reported that 10% of Internet users have Javascript disabled. ...and thanks to the Trap17 member who pointed out that CSS could be used thusly. To be fair enogh, the use of CSS to produce rollover images is a good lesson to study. But the importance of Javascript, so far as web programming is concerned, can not be denied as Javascript helps us to make our webpages more interactive. Because Javascript helps us to detect an event such as ,when the user clicks on a link or button, submits a form, moves the mouse, or loads a page and even unloads a page, Javascript detects such events and helps us to add interactivity in the wbpages accordingly. That is why, modern days website browsing has become much more interesting. So as I think, use of CSS and Javascript will go side-by-side despite of certain disadvantages like unavailibility of 100% Browser support in both the cases. I have found a well to read Javascript tutorial in www.PageResource.com. So, if anyone wants to know more about Javascript, please check out that link. |
|
|
|
Feb 13 2006, 02:58 AM
Post
#9
|
|
|
Whitest Black Mage Group: [MODERATOR] Posts: 1,381 Joined: 20-May 05 From: NB, Canada Member No.: 5,281 myCENTs:93.97 |
I've been toying around with different css stuff lately, might have to give that a try... personally I can't see it being useful for me but I can imagine alot of different ways it would be interesting, good stuff indeed. If I have any questions I'll harass you in a day or two lol.
|
|
|
|
Feb 13 2006, 04:23 AM
Post
#10
|
|
|
Absolute Newbie Group: Admin Posts: 888 Joined: 20-February 05 From: Indianapolis, Indiana, USA (Midwest) Member No.: 2,714 myCENTs:35.43 |
I'm a bit of a fan of the CSS image rollover effect. I guess in theory, you design your entire website using a single image.
I mean if you placed every graphic you needed in a single image and noted the coordinates for each item, it would work. I created a push button effect with my CSS. My Website: VW One Feel free to take a look at the CSS file and image to get a better idea of how it works. If you don't know how to find this information, view the page source in your browser. I like the feature becasue I don't have to keep track of as many images. It is a lot easier to code than JavaScript and it will work on all of my pages with just a link to the CSS file. I know that I can write a JavaScript file and link to it but I still find the CSS easier to use. I reserve JavaScript for things that CSS can't do. I've not had any compatability issue with modern browsers other than IE being a pain to code for. vujsa |
|
|
|
![]() ![]() |
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
Similar Topics
| Topic Title | Replies | Topic Starter | Views | Last Action | |||
|---|---|---|---|---|---|---|---|
![]() |
18 | vicky99 | 7,381 | 16th November 2009 - 03:48 PM Last post by: starscream |
|||
![]() |
7 | sxyloverboy | 4,490 | 5th November 2009 - 08:15 PM Last post by: iG-Christian Harkness |
|||
![]() |
2 | Jimmy89 | 2,357 | 4th November 2009 - 10:25 PM Last post by: HannahI |
|||
![]() |
12 | tansqrx | 9,135 | 1st November 2009 - 06:02 PM Last post by: iG-Dave |
|||
![]() |
4 | Aditya | 2,770 | 30th October 2009 - 03:21 AM Last post by: iG-ramu |
|||
![]() |
2 | rohitlocal | 92 | 23rd September 2009 - 02:46 PM Last post by: starscream |
|||
![]() |
4 | arkad | 3,076 | 15th September 2009 - 09:52 AM Last post by: iG-Miles |
|||
![]() |
4 | SunBlind | 1,611 | 26th August 2009 - 11:01 AM Last post by: iG-yazid |
|||
![]() |
7 | whistle | 2,701 | 25th August 2009 - 06:24 AM Last post by: iG- |
|||
![]() |
7 | BHerath | 1,061 | 19th August 2009 - 01:07 PM Last post by: iG-nick |
|||
![]() |
18 | webguide | 5,934 | 15th August 2009 - 04:07 PM Last post by: iG-Sherry |
|||
![]() |
16 | NoMore | 4,145 | 10th August 2009 - 09:04 PM Last post by: iG-BayBritBameBrogrammer |
|||
![]() |
10 | better | 1,611 | 9th August 2009 - 08:52 AM Last post by: iepbunleng016 |
|||
![]() |
2 | turbopowerdmaxsteel | 8,202 | 23rd July 2009 - 06:02 AM Last post by: iG-omar shan |
|||
![]() |
53 | WeaponX | 16,831 | 19th July 2009 - 01:34 AM Last post by: iG-William |
|||
|
Lo-Fi Version | Time is now: 24th November 2009 - 10:58 PM |
© 2009 AstaHost: Free Web Hosting & Technical Discussion, Free Web Hosting. a member of xisto.
Powered by Invision Board. Skin: IPB Forum Skins
Expand / Collapse Navigation


Aug 31 2005, 01:18 AM








