Solved

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

Posted on 2010-09-14
7
316 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 83

Accepted Solution

by:
Dave Baldwin earned 125 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 125 total points
ID: 33674721
Use php or javascript for conditional loop for image
0
 
LVL 31

Assisted Solution

by:Marco Gasi
Marco Gasi earned 125 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 14

Assisted Solution

by:Designbyonyx
Designbyonyx earned 125 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…

863 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now