Solved

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

Posted on 2010-09-14
7
312 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 82

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 30

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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 30

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 30

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

706 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

18 Experts available now in Live!

Get 1:1 Help Now