Would it be possible to apply a CSS class to either the <img>
or its container <div>
with javascript or JQuery, based on the filename of the <img>
src?
Could you assign a (already existing) CSS class to the <img src="...-A.jpg">
or its parent <div>
when i.e. A is present within the filename?
To add to this idea
Would it be possible to not only apply the styling automatically like that, but also create the whole <img>
tag? Ideally I would have different 'project' pages, on which I'd link an images folder i.e. images/project-1 to a <div id="image-container">
.
Could you use Javascript to create the subsequent <div><img/></div>
structure within the parent container <div>
? Or would this have to be some sort of PHP input?
Say you'd have;
.class-for-A {
width:200px;
}
.class-for-B {
width:400px;
}
.class-for-C {
width:600px;
}
<div id="image-container">
<!--(this section to be created automatically, and apply styles subsequently based on file name end)-->
<div>
<img src="img-filename-123-B.jpg"/>
</div>
<div>
<img src="img-filename-456-B.jpg"/>
</div>
<div>
<img src="img-filename-789-C.jpg"/>
</div>
<div>
<img src="img-filename-789-A.jpg"/>
</div>
It's the idea that A, B, C, are only used to indicate a class styling, instead of a sequence. Each img or div could in this way be styled automatically, functioning as a sort of light content management system (so there might ever only be three css class styles (A, B, C), but they would be re-used multiple times on different multiple images/divs).
This was just a thought I had, and I was curious to see if anyone had any thoughts on this.