Nov 22, 2009
Pages: 1, 2

Creating Rollover Images With Css - Eliminate the need for Javascript

free web hosting

Read Latest Entries..: (Post #12) by Josh-MOD on Aug 15 2006, 09:37 AM.
Thanx for that tutorial. i really needed that. good job
Read the FIRST post of this Topic. - Express your Opinion! Contribute Knowledge :-).

Open Discussion & Free Web Hosting > Computers & Tech > How-To's and Tutorials > Websites and Web Designing

Creating Rollover Images With Css - Eliminate the need for Javascript

clagnol
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.

 

 

 


Comment/Reply (w/o sign-up)

EdgeXC
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.

Comment/Reply (w/o sign-up)

mayank
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.

Comment/Reply (w/o sign-up)

twitch
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.

Comment/Reply (w/o sign-up)

jlhaslip
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.

Comment/Reply (w/o sign-up)

Quatrux
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. wink.gif and wait a minute, does :hover work normally with IE ? I think only with anchors.. sad.gif but I just checked your site and it works, both on Opera and IE.

Comment/Reply (w/o sign-up)

Kushika
QUOTE(Quatrux @ Jan 6 2006, 02:02 PM)
there are browsers with no css support, but with some kind of javascript support.
*



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?

Comment/Reply (w/o sign-up)

sid.calcutta
QUOTE(clagnol @ Aug 31 2005, 07:48 AM) *

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.

 

 

 


Comment/Reply (w/o sign-up)

Jeigh
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.

Comment/Reply (w/o sign-up)

vujsa
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. laugh.gif

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

Comment/Reply (w/o sign-up)

Latest Entries

Josh-MOD
Thanx for that tutorial. i really needed that. good job

Comment/Reply (w/o sign-up)

KDEWolf
Really ingenious...

I used to love Javascript and tables, but nowadays CSS is just king! Debugging JS code was really painful, with 'super' self-explanatory messages. Tables just added lots and lots of Kb to each page file size, and would break easily with a bigger image or word. Too bad I don't have the enough time to really master CSS.

But is there any big advantage on having one huge image? Or is this just for ease of use and less files to care about? I suppose it could take the overall file size down, but multiple smaller images load faster due to various browser connections with the web server, don't they? Also, how does this behave with animated GIFs (hehehe animated gif buttons are really old school)? Whoa, so many questions. Time to stop. =p

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Pages: 1, 2
Similar Topics

Keywords : creating, rollover, images, css, eliminate, javascript

  1. Show External Images Without Hotlinking!
    (13)
  2. Creating Your Own Simple But Effective Site
    To be resumed soon (26)
    Creating your own UKISS site from beginning to end Contents So that you know
    what is happening and when I’ve compiled this contents section. It will also help you got to
    the parts that you need without scrawling through everything. Introduction Design Step 1
    – Starting Fireworks and creating your canvas Step 2 – Making a base on which to work
    on Step 3 – Head’s up; start with the logo Step 4 – Finding your way;
    creating a menu Step 5 – Eyes to the centre; work on the main column Step 6....
  3. Creating A Simple But Effective Website
    Part 1 - Design (10)
    WARNING: This is a VERY image heavy tutorial and will take time to complete Topic closed
    until I can find the time to complete it, and I am getting mad with the large scale plagrism of
    other articles. Also, the images will no longer work, as I have changed domain name and also
    removed the images to make space. Creating a basic but effective website For beginners
    Introduction: Ok, so maybe you want to make a website that is “worthy” of the web. That is to say,
    you have made small taster sites before in FrontPage or something basic like it. And realised t....
  4. Creating Tooltips
    DHTML, HTML, CSS, Javascript... (7)
    Here is a little tutorial to make those small yellow-background boxes (tootltips) that pop-up for
    some links that describe them when you hover the mouse over them, it uses DHTML, CSS, HTML, and
    Javascript, so it gives us a much more wide range than my previous tutorials that just where on
    HTML. OK, so here we go... Put this right under CODE var offsetxpoint=-60 //Customize x
    offset of tooltip var offsetypoint=20 //Customize y offset of tooltip var ie=document.all var
    ns6=document.getElementById && !document.all var enabletip=false if (ie||ns6) var tipobj=doc....
  5. Three Html/ Css/ Javascript Tutorials
    (6)
    Here are some tutorials that always get great results when I post them. Lesson 1 HTML means Hyper
    Text Markup Language. HTML is a very common language used for many websites, is the base for more
    complicated and powerful langauges like php, HTML can seem hard, but you will find it is one of the
    easiest langauges one can learn. The core of HTML is the tag, a tage is just a set of two
    arrows-like brackets created by hitting Shift and the comma key, or Shift and the period key. They
    look like this... HTML HTML > Tags start a change in the way a webpage ....
  6. Creating A Css Rollover Menu (with Table Cells)
    for those bandwidthed challenged (9)
    Ive found this code very usefull when it comes to clients who cant afford Flash (and I hate
    JavaScript rollovers as they only work half the time and when you hold the mouse over the button for
    5 seconds) When your done here you should be able to create a menu that looks like the following:
    click here to see what it looks like Step 1: setting up the framework Get the framework in
    there for the script to work , I generally link to my stylesheets externally so I will show you how.
    Now open a simple text editor such as Notepad. set up your page with the following bas....
  7. Css Rollover Menu (with Background)
    bandwidth friendly rollover (0)
    Ive found this code very usefull when it comes to clients who cant afford Flash (and I hate
    JavaScript rollovers as they only work half the time and when you hold the mouse over the button for
    5 seconds) When your done here you should be able to create a menu that looks like the following:
    click here to see what it looks like Step 1: setting up the framework Get the framework in
    there for the script to work , I generally link to my stylesheets externally so I will show you how.
    Now open a simple text editor such as Notepad. set up your page with the following bas....
  8. Creating A Webpage Using Photoshop
    (4)
    I've read that this can be done with greater ease by using Ready Image, but since I'm more
    familiar with PS, I shall use PS as the guide. This guide does make a few assumptions :: 1) You
    already knew how to use Photoshop. 2) You already knew how to write HTML codes 3) You knew both of
    the above but did not ralise that it can be done .. Thus, I shall not touch on those 2 topics, as
    books a thousand pages thick have been written on them. So, I would wanna waste my time and yours
    and all the disksapce that could be used to host some useful stuff. 01:. Open the....
  9. This Page Was Last Modified On.....
    useful javascript... check it out (4)
    This javascript will show when the page was last modified. You can replace "This page was last
    updated on" with your own message.. CODE  function initArray() {        this.length =
    initArray.arguments.length      for (var i = 0; i      this = initArray.arguments   }   var
    DOWArray = new initArray("Sunday","Monday","Tuesday","Wednesday",                              
     "Thursday","Friday","Saturday");   var MOYArray = new
    initArray("January","February","March","April",                              
     "May","June","July","August","September",         ....
  10. Creating A Color Combination
    Guide to color combinations (18)
    Ever been to a website that is barely readable because of the bad color design? Well here's some
    tips to make sure that you don't fall into the same trap. * Black text on a white background,
    while not exciting, is the most practical color combination. * Try and not use more then four
    colors on your website, too many can be disorientating for the user. * Find out what each color
    represents to the users mind. For example green represents wealth while red represents daring. *
    Don't use yellow for web page backgrounds. * Take a look at Visibone or get a....
  11. Creating A Roll-over Effect With Text
    Save time and bandwidth-simple scripting (11)
    This short, but consise tutorial presents how to create a dynamic navigation bar using simple
    scripting verses using an image roll-over script. Using text instead of images offers 3 benefits
    while sacrificing only a little in design. The end resault is a navigation bar that looks great,
    dosen't bog the server down with images, loads fast, and is search engine friendly. In addition,
    you save time by not having to design two images for every link required. Using simple combination
    of Html, CSS, and Javascript we are able to create links in which both the color of th....
  12. Add Favicon To Your Site
    Creating, Converting to icon, Setup (39)
    Have you ever wondered how to get those icons displayed in your address bar for your own site? If
    you do not know what I mean, you could possibly have a browser that does not support favicon.ico or
    you just have not noticed. If you visit Google they should have a favicon in their address bar,
    if it's not displaying just goto this place to get the idea of what it would look like, but in
    your address bar, it should show just before the http part but sometimes it does not show so what I
    want to do is show you how you can force it to be shown on browsers that sup....

    1. Looking for creating, rollover, images, css, eliminate, javascript

See Also,

*SIMILAR VIDEOS*
Searching Video's for creating, rollover, images, css, eliminate, javascript
advertisement



Creating Rollover Images With Css - Eliminate the need for Javascript

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com