向溢出框中的图像添加叠加层
Adding overlay to images in overflow box
每张图片都应该有一个透明的黑色叠加层,中间有一个白色数字,例如“100”、“200”等。这个数字代表解锁图片所需的点数。我怎样才能做到这一点?
HTML
<div class="wrapper">
<div class="scrolls">
<img src="http://placehold.it/150x150" style="height:100px"/>
<img src="http://placehold.it/150x150" style="height:100px"/>
<img src="http://placehold.it/150x150" style="height:100px"/>
<img src="http://placehold.it/150x150" style="height:100px"/>
<img src="http://placehold.it/150x150" style="height:100px"/>
<img src="http://placehold.it/150x150" style="height:100px"/>
<img src="http://placehold.it/150x150" style="height:100px"/>
<img src="http://placehold.it/150x150" style="height:100px"/>
</div>
</div>
CSS
.wrapper {
background:#f4f4f4;
margin: auto;
text-align: center;
position: relative;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
margin-bottom: 20px !important;
width: 550px;
padding-top: 5px;
}
.scrolls {
overflow-x: scroll;
overflow-y: hidden;
height: 150px;
white-space:nowrap
}
.imageDiv img {
margin: 2px;
max-height: 150px;
cursor: pointer;
display:inline-block;
*display:inline;
*zoom:1;
vertical-align:top;
}
您需要将每个图像包裹起来并叠加在一个 dividual div 中。然后叠加层绝对定位在图像上。
.wrapper {
background: #f4f4f4;
margin: auto;
text-align: center;
position: relative;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
margin-bottom: 20px !important;
width: 550px;
padding-top: 5px;
}
.scrolls {
overflow-x: scroll;
overflow-y: hidden;
height: 150px;
white-space: nowrap;
padding-bottom: 25px;
}
.imageDiv {
margin: 2px;
max-height: 150px;
cursor: pointer;
display: inline-block;
*display: inline;
*zoom: 1;
vertical-align: top;
position: relative;
}
.imageDiv .overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.25);
line-height: 150px;
color: transparent;
font-size: 2em;
text-align: center;
transition: all .5s ease;
}
.imageDiv:hover .overlay {
background: rgba(0, 0, 0, 0.55);
color: white;
;
}
.imgaDiv img {
display: block;
}
<div class="wrapper">
<div class="scrolls">
<div class="imageDiv">
<img src=" http://placehold.it/150x150 " />
<div class="overlay">100</div>
</div>
<div class="imageDiv">
<img src=" http://placehold.it/150x150 " />
<div class="overlay">100</div>
</div>
<div class="imageDiv">
<img src=" http://placehold.it/150x150 " />
<div class="overlay">100</div>
</div>
<div class="imageDiv">
<img src=" http://placehold.it/150x150 " />
<div class="overlay">100</div>
</div>
<div class="imageDiv">
<img src=" http://placehold.it/150x150 " />
<div class="overlay">100</div>
</div>
<div class="imageDiv">
<img src=" http://placehold.it/150x150 " />
<div class="overlay">100</div>
</div>
<div class="imageDiv">
<img src=" http://placehold.it/150x150 " />
<div class="overlay">100</div>
</div>
<div class="imageDiv">
<img src=" http://placehold.it/150x150 " />
<div class="overlay">100</div>
</div>
</div>
</div>
对于 refinement/enhancement,您可以取消实际的覆盖 div 并改用伪元素..如果它只是样式。技术保持不变。
每张图片都应该有一个透明的黑色叠加层,中间有一个白色数字,例如“100”、“200”等。这个数字代表解锁图片所需的点数。我怎样才能做到这一点?
HTML
<div class="wrapper">
<div class="scrolls">
<img src="http://placehold.it/150x150" style="height:100px"/>
<img src="http://placehold.it/150x150" style="height:100px"/>
<img src="http://placehold.it/150x150" style="height:100px"/>
<img src="http://placehold.it/150x150" style="height:100px"/>
<img src="http://placehold.it/150x150" style="height:100px"/>
<img src="http://placehold.it/150x150" style="height:100px"/>
<img src="http://placehold.it/150x150" style="height:100px"/>
<img src="http://placehold.it/150x150" style="height:100px"/>
</div>
</div>
CSS
.wrapper {
background:#f4f4f4;
margin: auto;
text-align: center;
position: relative;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
margin-bottom: 20px !important;
width: 550px;
padding-top: 5px;
}
.scrolls {
overflow-x: scroll;
overflow-y: hidden;
height: 150px;
white-space:nowrap
}
.imageDiv img {
margin: 2px;
max-height: 150px;
cursor: pointer;
display:inline-block;
*display:inline;
*zoom:1;
vertical-align:top;
}
您需要将每个图像包裹起来并叠加在一个 dividual div 中。然后叠加层绝对定位在图像上。
.wrapper {
background: #f4f4f4;
margin: auto;
text-align: center;
position: relative;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
margin-bottom: 20px !important;
width: 550px;
padding-top: 5px;
}
.scrolls {
overflow-x: scroll;
overflow-y: hidden;
height: 150px;
white-space: nowrap;
padding-bottom: 25px;
}
.imageDiv {
margin: 2px;
max-height: 150px;
cursor: pointer;
display: inline-block;
*display: inline;
*zoom: 1;
vertical-align: top;
position: relative;
}
.imageDiv .overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.25);
line-height: 150px;
color: transparent;
font-size: 2em;
text-align: center;
transition: all .5s ease;
}
.imageDiv:hover .overlay {
background: rgba(0, 0, 0, 0.55);
color: white;
;
}
.imgaDiv img {
display: block;
}
<div class="wrapper">
<div class="scrolls">
<div class="imageDiv">
<img src=" http://placehold.it/150x150 " />
<div class="overlay">100</div>
</div>
<div class="imageDiv">
<img src=" http://placehold.it/150x150 " />
<div class="overlay">100</div>
</div>
<div class="imageDiv">
<img src=" http://placehold.it/150x150 " />
<div class="overlay">100</div>
</div>
<div class="imageDiv">
<img src=" http://placehold.it/150x150 " />
<div class="overlay">100</div>
</div>
<div class="imageDiv">
<img src=" http://placehold.it/150x150 " />
<div class="overlay">100</div>
</div>
<div class="imageDiv">
<img src=" http://placehold.it/150x150 " />
<div class="overlay">100</div>
</div>
<div class="imageDiv">
<img src=" http://placehold.it/150x150 " />
<div class="overlay">100</div>
</div>
<div class="imageDiv">
<img src=" http://placehold.it/150x150 " />
<div class="overlay">100</div>
</div>
</div>
</div>
对于 refinement/enhancement,您可以取消实际的覆盖 div 并改用伪元素..如果它只是样式。技术保持不变。