Solved

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

Posted on 2010-09-14
7
322 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Split wordpress loop 35 56
Row insertion failed. Array 5 48
Link failure 16 34
Html Newline 7 21
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to dynamically set the form action using jQuery.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

828 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