[英]Make background image transparent without affecting foreground text in Jekyll theme
[英]Overlaying image without affecting transparent
我想使用CSS为图像着色,但又不影响其透明部分。
例如:如果我在具有透明背景的图像中没有棕色的正方形,我只想将正方形变成另一种颜色。
我已经找到了本指南(http://css-tricks.com/forums/discussion/10828/color-overlay-img/p1),但它也会影响透明部分。
提前致谢
您可以做的是在图像下方的要着色的尺寸处放置一个<div>
。 这是我会做:
<div class="image">
<div class="colour"></div>
<img src="[..].png" alt="Some image" />
</div>
然后是CSS:
.image{
width: 100px; /* The image width */
height: 100px; /* The image height */
position: relative;
}
.image .colour{
width: 30px; /* Width of the part you want to colour */
height: 30px; /* Height of the part you want to colour */
position: absolute;
top: 35px; /* Y coordinate */
left: 35px; /* X coordinate */
}
.image img{
position: absolute;
top: 0;
left: 0;
z-index: 1; /* Place above the coloured part */
}
如果区域是矩形
如果区域是非矩形的
我不相信有单独使用CSS的通用方法(无需触摸HTML或使用多个图像文件,画布或SVG或JS或jQuery)。 如果无法触摸HTML源代码,则可以使用JS或jQuery动态修改HTML。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.