Continuing the theme of the translucent frame inside the picture - and if you need a frame with rounded corners, or completely round, i.e. the rectangular photo center is clean, the rest of the space is occupied by a translucent frame, the inner part is in the form of a circle?
4 answers
It is possible and on without SVG ..
.img-block { display: block; width: 150px; height: 150px; position: relative; overflow: hidden; } .img-block img { display: block; width: 100%; height: 100%; border: 0; object-fit: cover; } .img-block .border { display: block; width: 100%; height: 100%; border-radius: 50%; box-shadow: 0 0 0 100px rgba(255, 0, 0, .5); position: absolute; left: 0; top: 0; right: 0; bottom: 0; } <div class="img-block"> <img src="http://via.placeholder.com/150x150"> <div class="border"></div> </div> - You can replace
<div class="border"></div>:before- CbIPoK2513 - @Arthur, does religion not allow writing styles in line? - CbIPoK2513
- This is called readability - Arthur
- Well, if only for this) - CbIPoK2513
- Edits are made to improve questions and answers (i.e. for good purposes) - Arthur
|
I will do it later on SVG . mix-blend-mode poorly supported, but the effects are incredible:
img { width: 480px; } .item { width: 480px; display: inline-block; position: relative; overflow: hidden; } .item:after { content: ""; display: block; width: inherit; height: 100%; background: rgba(255, 5, 255, .9); position: absolute; top: 0; left: 0; z-index: 1; mix-blend-mode: screen } .item:before { content: ""; display: block; width: 90%; height: 90%; background: rgba(250, 250, 250, 0.8); position: absolute; top: 50%; left: 50%; z-index: 2; transform: translate(-50%, -50%); border-radius: 50%; mix-blend-mode: color; } <div class="item"> <img src="https://cdn.wallaps.com/wallpapers/150000/144504.jpg" alt=""> </div> Second example:
img { width: 480px; } .item { width: 480px; display: inline-block; position: relative; overflow: hidden; } .item:after { content: ""; display: block; width: inherit; height: 100%; background: rgba(255, 5, 255, .9); position: absolute; top: 0; left: 0; z-index: 1; mix-blend-mode: darken; } .item:before { content: ""; display: block; width: 90%; height: 90%; background: url(https://cdn.wallaps.com/wallpapers/150000/144504.jpg); position: absolute; top: 50%; left: 50%; background-size: 100% 100%; z-index: 3; transform: translate(-50%, -50%); border-radius: 50%; } <div class="item"> <img src="https://cdn.wallaps.com/wallpapers/150000/144504.jpg" alt=""> </div> The third option:
img { width: 480px; } .item { width: 480px; display: inline-block; position: relative; overflow: hidden; } .item:after { content: ""; display: block; width: inherit; height: 100%; background: rgba(255, 255, 255, .0); position: absolute; top: 0; left: 0; z-index: 1; mix-blend-mode: color-dodge; filter: grayscale(0); } .item:before { content: ""; display: block; width: 90%; height: 90%; background: url(https://cdn.wallaps.com/wallpapers/150000/144504.jpg); position: absolute; top: 50%; left: 50%; background-size: 100% 100%; z-index: 3; transform: translate(-50%, -50%); border-radius: 50%; filter: grayscale(100); } <div class="item"> <img src="https://cdn.wallaps.com/wallpapers/150000/144504.jpg" alt=""> </div> |
SVG An example using mask :
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <defs> <mask id="mask"> <rect width="100%" height="100%" fill="rgba(255,255,255,0.5)"/> <circle r="75" cx="75" cy="75"/> </mask> </defs> <image xlink:href="http://pravetsresidence.bg/en/wp-content/uploads/2017/07/town-house-exterior1-150x150.jpg"/> <rect width="150px" height="150px" fill="white" mask="url(#mask)"/> </svg> - since you’ve done it on SVG, I won’t ... :)) - user33274
- one@ MaksimLensky, I had to answer for the activity)) - Arthur
- in Fox there is nothing to be seen at all .... a white window - user33274
|
You can also use an overlapping pseudo-element with an infinite shadow and border-radius :
body { margin: 0; } div { background-image: url("https://i.stack.imgur.com/sPNoH.jpg"); background-size: cover; height: 100vh; /* Указать нужную высоту и ширину здесь */ position: relative; } div:after { content: ""; /* накрыть картинку полностью */ position: absolute; top: 0; bottom: 0; left: 0; right: 0; /* бесконечная тень */ /* fallback для IE, так как IE не распознаёт единицы vmax */ box-shadow: 0 0 0 99999px rgba(255, 255, 255, .6); /* для остальных браузеров, которые понимают vmax */ box-shadow: 0 0 0 100vmax rgba(255, 255, 255, .6); border-radius: 50%; } <div></div> For some situations, a translucent radial gradient with a completely transparent area for the image ("cutout") is quite suitable for you:
body { margin: 0; } div { background-image: radial-gradient(transparent 70%, rgba(255, 255, 255, 0.6) 0), url("https://i.stack.imgur.com/sPNoH.jpg"); background-size: cover; height: 100vh; /* Указать нужную высоту и ширину здесь */ } <div></div> I use 0 as the second value ( rgba(255, 255, 255, 0.6) 0 ) in the radial gradient so as not to duplicate the first, since according to the specification the gradient step cannot be less than the previous value.
In the case of a color-stop before it.
- Doesn't
box-shadowaffect performance? - Arthur - @Arthur And where does the information that
box-shadowaffect performance come from? And compared to which method will it be slower? - Vadim Ovchinnikov - I found it on one site =) - "Everything that involves making changes / calculations before rendering the page will be labor-intensive for the browser. For example, box-shadow, border-radius, transparency." Suppose in comparison with your second variant :) (Or maybe I misunderstood these words) - Arthur
- one@Arthur Well then your comment is suitable for all other answers too :) Then the ideal answer would be to edit the image in the editor and use it. Gradient calculation does not seem to be a cheap operation. And the answer of Maxim Lensky, most likely, is generally a performance “killer”, since mixing of pictures in general seems to me to be an even more complicated operation. - Vadim Ovchinnikov
- But creatively: D (Maxim answers). It seems in all cases it is advantageous to use pictures)) - Arthur
|
