0

I am looking for how to add a class in css which matches to a specific path (For example, the name of my path is "cities" and I would like to apply to it an other color of stroke or fill. I try it by different ways, but no result. Is it possible?

Thanks in advance!

Amar
  • 11,930
  • 5
  • 50
  • 73
maeva
  • 17
  • 2

3 Answers3

1

This is a rudimentary solution, it won't handle addition of classes, just replacements based on your path.

Create two directories, one called 'red', one called 'blue'. Create pages in each with the following in them. They will read the path and add the class into the DIV called #content.

Here's a Fiddle (note: with a hardcoded path so it works) to demonstrate.

Hope this helps.

<!DOCTYPE HTML>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
    .red {background-color:red}
    .blue {background-color:blue}
    .green {background-color:green}
    </style>
</head>
<body>
<div id="content">this is the content</div>
    <script type="text/javascript">
     var locationpath =  ""+window.location.pathname+"";
     var options = ['red','blue','green'];
     for (var i =0;i<options.length;i++) {
         if (locationpath.indexOf(options[i])>0) {
            document.getElementById('content').setAttribute('class',options[i]) ;
         } 
     }

    </script>
</body>
</html>
A.M. D.
  • 928
  • 6
  • 10
0

I am not Exactly sure what you are asking for, pleases post some of your code. But I think you can accomplish what you want by creating multiple classpaths in CSS like this:

#something {
  width: 200px;
  font-size: 12px;
     }

#something.black {
   color: #000000
     }

#something.white {
   color: #FFFFFF
     }

And the HTML would be like this:

<h1 id="something" class="black">This Should Be Black</h1>

Etc.

mrtriangle
  • 542
  • 11
  • 28
  • 1
    In fact, after getting the id by the script from AMD bellow, it's possible to add it in the css. (And sorry for my english writting) – maeva Nov 07 '12 at 21:56
0

What do you mean by "path" ?

For example, the name of my path is "cities" and I would like to apply to it an other color of stroke or fill.

If you try to focus elements by "name" you shound use Jquery.

Example:

<input type="text" name="tiluuu"/>

And Jquery

$('input').attr('name','tiluuu').css({'color':'red'});

  • Sorry for my explaination. I said "path" because I use a SVG document and I would add a class in the css to it to change the color of my drawing. – maeva Nov 07 '12 at 21:53