I plan to create a custom photo gallery for a friend, and I know exactly how I will create the HTML, however I ran into a little CSS problem.
(I would rather not have a page style that relies on jQuery, if possible)
My question concerns:
CSS
Data-Attribute Background-image HTML in CSS
I use this format for my html thumbnails:
<div class="thumb" data-image-src="images/img.jpg"></div>and I assume that CSS should look something like this:
.thumb { width:150px; height:150px; background-position:center center; overflow:hidden; border:1px solid black; background-image: attr(data-image-src); }
My goal is to take
data-image-src from
div.thumb in my HTML file and use it for each
div.thumb (s)
Background-image source in my CSS file.
Here is the Codepen pen to get a dynamic example of what I'm looking for:
http://codepen.io/thestevekelzer/pen/rEDJv
css3 background-image custom-data-attribute
StephenKelzer Mar 31 '13 at 21:08 2013-03-31 21:08
source share