Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

CSS selector class to use an alternate image if another does not exist

Posted on 2010-09-14
7
Medium Priority
?
336 Views
Last Modified: 2012-05-10
I need the CSS selector class to check if an image exists, if it does NOT then use another image.

For example, if the image in path /images/SPANISH/submit.png exists then use /images/spanish/submit.png else use /images/ENGLISH/submit.png

Code base is PHP, Apache
0
Comment
Question by:pmsguy
7 Comments
 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 33674549
CSS doesn't have any conditional programming statements in it.  Conditional statements for IE only work in the HTML file.
0
 

Assisted Solution

by:web2developer
web2developer earned 500 total points
ID: 33674721
Use php or javascript for conditional loop for image
0
 
LVL 31

Assisted Solution

by:Marco Gasi
Marco Gasi earned 500 total points
ID: 33674725
In these cases you have to use php to check for files and write css statements inline.

<?php
    if (file_exists("path_to_your_first_file")){
        echo "<div id='whatbackground' style='background:url('path_to_your_second_file'>";
    }elseif (file_exists("path_to_your_first_file")){
        echo "<div id='whatbackground' style='background:url('path_to_your_second_file'>";
    }else{
        echo "<div id='whatbackground' style='background:transparent>";
    }
?>
your content here
</div>

If you prefer, you can check for files as shown above, but within head tag and include different css files accordingly with file_exists result.

Hope this helps
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 14

Assisted Solution

by:Designbyonyx
Designbyonyx earned 500 total points
ID: 33674752
You are better off having a single php file deliver your images, and you would call on it like so:

getfile.php?file=submit.png&lang=es

Then in php, you could check to see if the file exists:

(writing by hand... may not be correct, but should give you the right idea)
$file = $_GET["file"];
$lang = $_GET["lang"];
$defaultLang = "ENGLISH";

$dir = "";
$filePath = "";

switch($lang) {
    case "es":
        $dir = "SPANISH";
    case "en"
        $dir = "ENGLISH";
    default:
        $dir = $defaultLang;
}

$filePath = "/". $dir ."/". $file;
if( !file_exists($filePath) ) {
    $filePath = "/" . $defaultLang . "/" . $file;
}

// Load the file and stream it to the browser here.  
// Be sure to set the correct MIME type and such

Open in new window

0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 33674815
Since your question seems to be related to a multi-language site, maybe you can consider interesting read this article:
http://www.experts-exchange.com/A_3674.html about "How To Implement a multi-language site/application".
Cheers
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 33753522
Have you solved your problem?

Regards
0
 

Author Closing Comment

by:pmsguy
ID: 33754140
I am sure there is some dynamic CSS I can use to solve this issue
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Find out what you should include to make the best professional email signature for your organization.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

782 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question