Question:

I was reading, "Use CSS Images instead of IMG tag: An easy way to..

by  |  earlier

0 LIKES UnLike

speed up the rendering of an image is to simply call as a background of a div tag.", and elsewhere I read that that if you use CSS for images the images will come up last (after your text), which is what I want.

But I don't want to load up my css page with a long list of images (40), becuase the CSS page is loaded into the visitor's browser, and so will slow the length of time it takes to bring up my site. I really don't want to use sprites. Isn't there a way where I can load the images into a PHP includes file and refer to the includes file in the CSS, but what code would I use in the main coding (HTML) from page to page to bring up the different images for different pages?

Thanks for the help

 Tags:

   Report

1 ANSWERS


  1. You could pass a parameter in your URLs query string, like:

    mypage.php?img=1

    Then you can name your CSS file something like:

    style.css.php

    In your CSS file you can do something like:

    $img = $_GET['img'];

    If ($img > 0 && $img <  5) {

    print "#myDiv { background-url: image1.jpg }";

    } else {

    print "#myDiv { background-url: image2.jpg }";

    }

    Or you know, use whatever argument you want within your if statement.

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.