admin管理员组文章数量:1410681
I'm using this css to add a watermark to my images on my site, the problem is that when it fits on a phone screen the watermark logo looks bigger almost taking up the whole thumbnail I would really appreciate your support
.watermarked {
position: relative;
}
.watermarked:after {
content: "";
display: block;
width: 100%;
height: 100%;
position: absolute;
top: 0px;
left: 0px;
background-image: url(".png");
background-size: 100px 100px;
background-position: 30px 30px;
background-repeat: no-repeat;
opacity: 0.7;
}
<div class="watermarked">
<img src=".jpeg" alt="Photo">
</div>
I'm using this css to add a watermark to my images on my site, the problem is that when it fits on a phone screen the watermark logo looks bigger almost taking up the whole thumbnail I would really appreciate your support
.watermarked {
position: relative;
}
.watermarked:after {
content: "";
display: block;
width: 100%;
height: 100%;
position: absolute;
top: 0px;
left: 0px;
background-image: url("https://i.imgur/5GQA67n.png");
background-size: 100px 100px;
background-position: 30px 30px;
background-repeat: no-repeat;
opacity: 0.7;
}
<div class="watermarked">
<img src="https://i.imgur/xDlSplX.jpeg" alt="Photo">
</div>
Share
Improve this question
edited Mar 11 at 9:16
Ori Drori
194k32 gold badges238 silver badges229 bronze badges
asked Mar 11 at 9:04
CovadolaCovadola
134 bronze badges
1
|
1 Answer
Reset to default 1The .watermarked
element should fit the child image's width and height. Set the background-size
and background-position
using percent, so they would change according to the parent's size:
.watermarked {
position: relative;
width: fit-content;
height: fit-content;
}
.watermarked:after {
content: "";
display: block;
position: absolute;
inset: 0;
background-image: url("https://i.imgur/5GQA67n.png");
background-size: 20%;
background-position: 3% 3%;
background-repeat: no-repeat;
opacity: 0.7;
}
img {
object-fit: cover;
}
.img1 {
width: 100px;
height: 100px;
}
.img2 {
width: 300px;
height: 300px;
}
<div class="watermarked">
<img class="img1" src="https://i.imgur/xDlSplX.jpeg" alt="Photo">
</div>
<div class="watermarked">
<img class="img2" src="https://i.imgur/xDlSplX.jpeg" alt="Photo">
</div>
<div class="watermarked">
<img src="https://i.imgur/xDlSplX.jpeg" alt="Photo">
</div>
本文标签: htmlHow to make watermark responsiveStack Overflow
版权声明:本文标题:html - How to make watermark responsive? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744805536a2626124.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
20% auto
; and also change background-position to5% 5%
– Coco Q. Commented Mar 11 at 9:16