我计划为一位朋友构建一个自定义图片库,我确切地知道我将如何生成HTML,但是我遇到了CSS的一个小问题.
(如果可能的话,我不希望页面样式依赖于jQuery)
My question regards:
Data-Attribute
in HTMLBackground-image
in CSS
I am using this format for my html thumbnails:
<div class="thumb" data-image-src="images/img.jpg"></div>
我假设CSS应该如下所示:
.thumb {
width:150px;
height:150px;
background-position:center center;
overflow:hidden;
border:1px solid black;
background-image: attr(data-image-src);/*This is the question piece*/
}
My goal is to take the
data-image-src
from the div.thumb
in my HTML file and use it for each div.thumb
(s) background-image
source in my CSS file.
Here is a Codepen Pen in order to get a dynamic example of what I am looking for:
http://codepen.io/thestevekelzer/pen/rEDJv