I have a single element with a non-repeating background-image
at background-position: 4px 4px
. The image is an avatar and to it's right is a single paragraph with margin-left: 120px
so the text doesn't flow over the background-image
. I've already accomplished the effect on an image element however to solidify my comprehension of CSS masks I wanted to determine how to apply this same effect on a background-image
. Here is my current code (fuchsia used only for my debugging and now here to help visualize the problem):
/***
-webkit- prefixes automatically appended by my system software.
Testing with Waterfox first, Chrome second.
***/
background-color: #f0f;
background-image: url(avatar.png);
mask-image: radial-gradient(ellipse at center, rgba(255,255,255,1) 1%,rgba(255,255,255,1) 50%,rgba(255,255,255,0) 70%,rgba(255,255,255,0) 100%);
mask-position: 4px 4px;
mask-size: 100px 100px;
Setting mask-repeat: no-repeat;
hides everything else (e.g. the child paragraph element) and most other mask-repeat
values simply repeat the circle effect as demonstrated in the sample image. I've been going through Mozilla Developer Network's Mask documentation though nothing seems to help. Sure, I could mess around with CSS generated content however I wouldn't learn anything and limit my own design capabilities.
How do I only mask part of an element using CSS without hiding the rest of the element or it's child elements?
.preface {
overflow: auto;
}
.preface .synopsis {
background-color: #f0f;
background-image: url(https://picsum.photos/id/1074/110/110);
background-position: 4px 4px;
background-repeat: no-repeat;
float: left;
height: 108px;
-webkit-mask-image: radial-gradient(ellipse at center, rgba(255, 255, 255, 1) 1%, rgba(255, 255, 255, 1) 50%, rgba(255, 255, 255, 0) 70%, rgba(255, 255, 255, 0) 100%);
-webkit-mask-position: 4px 4px;
-webkit-mask-size: 100px 100px;
mask-image: radial-gradient(ellipse at center, rgba(255, 255, 255, 1) 1%, rgba(255, 255, 255, 1) 50%, rgba(255, 255, 255, 0) 70%, rgba(255, 255, 255, 0) 100%);
mask-position: 4px 4px;
mask-size: 100px 100px;
min-height: 108px;
overflow: auto;
position: relative;
width: 75%;
}
<section class="preface">
<div class="synopsis">
<p>Some text.</p>
</div>
</section>