Solved

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

Posted on 2010-09-14
7
328 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

630 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