1

Let me try and explain what I mean here.... I have a lot of images on my page, and different paths where they are stored.

<img src="what/ever/folder/pic01.jpg">
<img src="and/even/longer/path/name/pic09.jpg">
<img src="what/ever/folder/pic01.jpg">
<img src="and/even/longer/path/name/pic09.jpg">

etc... they are scattered all over the long page

Would it be possible with CSS or HTML or.. to make a variable containing each path, and then use that in the HTML?

PATH01 = 'what/ever/folder/'
PATH02 = 'and/even/longer/path/name/'

And then do the images, styles etc..

<img src={PATH01}"pic01.jpg">

Or something like that? (am I making any sense?`hehe)

torbenrudgaard
  • 2,375
  • 7
  • 32
  • 53
  • 4
    Neither HTML nor CSS has any concept of a variable. You can do this with "templating" solutions (either server-side templating or client-side templating) like Handlebars. Also possible client-side with `document.write`, but it isn't pretty. :-) Note that client-side templating will rely on JavaScript. – T.J. Crowder Jul 19 '16 at 07:26
  • This might help http://stackoverflow.com/questions/15831657/creating-css-global-variables-stylesheet-theme-management – DreamTeK Jul 19 '16 at 07:31

3 Answers3

2

HyperText Markup Language, commonly abbreviated as HTML, is the standard markup language

This means that here are no vars in html. But there a lot of html server-side processors like php,node.js etc which can give you result you are looking for.

PHP example:

<?php
$path01 = 'some/path/';
?>

<img src="<?=$path01?>pic01.jpg">
<br/>
<img src="<?php echo $path01?>pic01.jpg">
Maksym Semenykhin
  • 1,924
  • 15
  • 26
2

good question, <base> is what you are looking for

Specify a default URL and a default target for all links on a page

http://www.w3schools.com/tags/tag_base.asp

in your case

<img src="what/ever/folder/pic01.jpg">

can be written in

<base href="http://whatever.com/what/ever/folder" />
<img src="pic01.jpg">

but <base> is a unique element in single page, which means you can have only one ENV variable set.

p.s. 99% of time we use html template system (php, jsp or react.js, handlebars) to solve this kind of problem in real life

FE Bear
  • 111
  • 3
0

No you can't do that using purely HTML or CSS. You could however do something like that using javascript or the server language of your choice.

Thijs
  • 3,015
  • 4
  • 29
  • 54