DivitoDesign

Everything for the Web Professional

CSS Image Preloader

Information about the Author:

Name:

URL: http://twitter.com/divitodesign

Description enjoy design, write articles, like typography, love football, keep chilling.

More on: CSS

43 Comments

  1. liam says:

    Excelent solution to a common problem, and a great way around it.

    Very nice, thanks for this.

  2. gilette says:

    Could you show me an exaple/website/ about it? Please…!
    Thx!

  3. chica says:

    this good sample!thanks alot..

  4. Alvin says:

    Well im not with you on the css part.

    My way is:
    div .loader{
    background-image:url(images/hover.gif);
    background-image:url(images/hover2.gif);
    background-image:url(images/hover3.gif);
    background-image:url(images/hover4.gif);
    display:none;
    }

  5. There are two ways to do the trick. I decided to go this way, but the way you provided is a good one as well. When you try it out, you’ll notice it works both ways. Thanks for your comment.

  6. gilette says:

    I do not speak well in English. “Samplesite?” PLS!!!

  7. Gilette, I understood. I will post some very soon.

  8. gilette says:

    Thanks a lot :)

  9. Michiel says:

    Even faster:

    ul li a{
    width:169px;
    text-decoration: none;
    padding: 0.3em 1em;
    color: #000;
    background:url(images/hover.gif);
    background:url(images/link.gif);
    }

    your browser will load the hover.gif, but it will display the link.gif. As that part is the last background property the css reads.

  10. That way is a possibility as well.

    Post updated with an example!

  11. gilette says:

    Thank you very much.

    But… the pre-loader.gif does not appear unfortunately when I click the button :(

  12. gilette says:

    Sorry….. I misunderstood all.

    I looked for it: http://www.webmasterworld.com/forum83/8261.htm

    but only with css/no js/.

  13. Xevo says:

    It would be better just 2 use one image for the links. Than just replace the image with image position when you hover and bingo! :]

  14. Herman says:

    Xevo, can you please show how to do that with a sample code?
    Thanks

  15. Kaylx says:

    If you wanna do what Xevo mentioned here’s the code:

    #navi ul li a
    {
    background: url(images/navi.gif) 0px 0px repeat-x;
    }

    #navi ul li a:hover
    {
    background-position: 0 -41px;
    }

    In this example the navigation links are 41px in height and navi.gif is 1px by 82px. The 1st 41px of the image are for the link background normally and the second 41px are for the link background when the user hovers over the link.
    The navigation link is obviously not 1px in width so i use ‘repeat-x’ so the image repeats across the whole link background.
    Anyway the main details are 1) ’0px 0px’ and 2) ’0px -41px’. These specify the image (navi.gif) relative to the link. Essentially 1) means the normal link image is shown and 2) moves the image up to show the hover image and hide the normal image.

  16. Ian says:

    hey wheres the code for this one?

    “We are going to add a pre-loader. Open up your HTML file and add the following codes just above your tag.”

    cant seem to see the codes.

    thanks man!

  17. Hi Ian – Great you mentioned this. When updating to the new theme, I think something might have gone wrong! Thank you.

  18. [...] wrote a tutorial about pre-loading images via CSS some time ago. This time we’ll use a slightly different approach. We will go deeper into the [...]

  19. Flaxton says:

    Anyway to make those battleground images into a link when clicked on?

  20. Yes, there is a way to do that. I haven’t really looked into that, but I’ll post a tutorial about this soon, I guess.

  21. [...] hover effect, but now the effect shows up when you click on an item. I also show you how to add a preloader to this [...]

  22. Being a coder since 2000 i can tell you that the preloader images should have each it’s own class… That’s just because the browsers keep upgrading all the time and the cascading bug/hack may not work in the nearest future.. Great idea though!

  23. Webagentur says:

    Thank you, but I still do not understand what is really good for?!

  24. I agree the best way to do it is using div instead frames.

  25. Neal G says:

    There’s no need for an extra div. You can just assign this to any current element on the page i.e

    html
    {
    background:url(images/hover.gif) no-repeat;
    background:url(images/hover2.gif) no-repeat;
    background:url(images/hover3.gif) no-repeat;
    background:url(images/hover4.gif) no-repeat;
    }

    Assuming you overwrite this later in your css file with another background image.

  26. Fred Dibnah says:

    Quick thanks for the code, saved me some work today.

  27. nadz says:

    hey very nice trick friend i loved it . Will be very helpful yar. And i liked you your css you are using to write codes in posts . can you share it :)

  28. Web Design says:

    You sure this will work better with Ajax based websites. I have worked with .net, and used its built in image loader tool under Ajax tool bar. This however seems to be a good replacement especially for PhP web sites. Thanks for the reference site.

  29. [...] CSS Image Preloader » DivitoDesign Pre-Load your Images using CSS. This fast solution adds a image pre-loader using the CSS language. [...]

  30. web design says:

    Good tip, been looking for a script like this to preload our navigation menu

  31. Igre says:

    This is great, thx!

  32. greetings says:

    how can create a div pre loader with jquery ?

  33. CSS spinners says:

    There is a whole generator of those things – http://cssload.net . They have both spinners and bars for loading in CSS

  34. agurchand says:

    Thanks for the great tutorial man.

Please Respond and Give your Opinion

We use Gravatar to handle our avatars. Get one there!