Reputation: 335
Can somebody tell me how to fix this margins of my ::before
element? Any margin: -2px
doesn't work, any paddings... when I resize page, margins are still visible, once at top of img, once on sides... SVG file doesn't have this blue lines on its sides.
.container {
background-color: #f7f7f7;
height: 1000px;
padding: 20px;
}
.media {
position: relative;
max-height: 408px;
height: 155px;
width: 200px;
margin: 0 auto;
}
.media img {
max-width: 100%;
height: 100%;
object-fit: cover;
}
.media::before{
content: "";
background-image: url(https://svgshare.com/i/HRx.svg);
position: absolute;
background-position: center center;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 10;
background-size: cover;
background-repeat: no-repeat;
}
<div class="container">
<div class="media">
<img src="https://i.imgur.com/iD4ERTU.jpg">
</div>
</div>
SVG
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="512" height="513" viewBox="0 0 512 513"><defs><style>.a{fill:#f7f7f7;}.b{fill:#004fa3;}.c{clip-path:url(#a);}.d{fill:#2699fb;}.e{clip-path:url(#b);}.f,.h{fill:none;}.f{stroke:#0092ff;}.g{stroke:none;}</style><clipPath id="a"><rect class="a" width="512" height="513"/></clipPath><clipPath id="b"><ellipse class="b" cx="193.129" cy="193.129" rx="193.129" ry="193.129" transform="translate(511.391 163.225) rotate(115)"/></clipPath></defs><g class="c"><path class="d" d="M104.741,309.74S-53.3,342.253,18.88,249.888,133.249,220.239,185.7,134.716,186.843-3.264,266.665.158s6.842,255.431,6.842,255.431Z" transform="translate(315.585 237.501) rotate(129)"/><path class="a" d="M-962-168h-512V-680h512v512Zm-257.146-435.439a180.791,180.791,0,0,0-163.286,103.993,178.856,178.856,0,0,0-6.01,137.662,178.855,178.855,0,0,0,93.092,101.592,178.531,178.531,0,0,0,75.969,16.911h.014A180.775,180.775,0,0,0-1056.1-347.274c41.954-89.971,2.89-197.3-87.08-239.254A178.493,178.493,0,0,0-1219.146-603.439Z" transform="translate(1474 680)"/><g transform="translate(330.302 352.173)"><ellipse class="d" cx="3.691" cy="3.691" rx="3.691" ry="3.691"/><ellipse class="d" cx="3.691" cy="3.691" rx="3.691" ry="3.691" transform="translate(0 79.363)"/><ellipse class="d" cx="3.691" cy="3.691" rx="3.691" ry="3.691" transform="translate(0 39.679)"/><ellipse class="d" cx="3.691" cy="3.691" rx="3.691" ry="3.691" transform="translate(39.68)"/><ellipse class="d" cx="3.691" cy="3.691" rx="3.691" ry="3.691" transform="translate(39.68 79.363)"/><ellipse class="d" cx="3.691" cy="3.691" rx="3.691" ry="3.691" transform="translate(39.68 39.679)"/><ellipse class="d" cx="3.691" cy="3.691" rx="3.691" ry="3.691" transform="translate(79.362)"/><ellipse class="d" cx="3.691" cy="3.691" rx="3.691" ry="3.691" transform="translate(79.362 79.363)"/><ellipse class="d" cx="3.691" cy="3.691" rx="3.691" ry="3.691" transform="translate(79.362 39.679)"/></g><g class="e"><g class="f" transform="translate(511.391 163.225) rotate(115)"><ellipse class="g" cx="193.129" cy="193.129" rx="193.129" ry="193.129"/><ellipse class="h" cx="193.129" cy="193.129" rx="192.629" ry="192.629"/></g><g transform="translate(330.302 352.173)"><ellipse class="d" cx="3.691" cy="3.691" rx="3.691" ry="3.691"/><ellipse class="d" cx="3.691" cy="3.691" rx="3.691" ry="3.691" transform="translate(0 79.363)"/><ellipse class="d" cx="3.691" cy="3.691" rx="3.691" ry="3.691" transform="translate(0 39.679)"/><ellipse class="d" cx="3.691" cy="3.691" rx="3.691" ry="3.691" transform="translate(39.68)"/><ellipse class="d" cx="3.691" cy="3.691" rx="3.691" ry="3.691" transform="translate(39.68 79.363)"/><ellipse class="d" cx="3.691" cy="3.691" rx="3.691" ry="3.691" transform="translate(39.68 39.679)"/><ellipse class="d" cx="3.691" cy="3.691" rx="3.691" ry="3.691" transform="translate(79.362)"/><ellipse class="d" cx="3.691" cy="3.691" rx="3.691" ry="3.691" transform="translate(79.362 79.363)"/><ellipse class="d" cx="3.691" cy="3.691" rx="3.691" ry="3.691" transform="translate(79.362 39.679)"/></g><g class="f" transform="translate(511.391 163.225) rotate(115)"><ellipse class="g" cx="193.129" cy="193.129" rx="193.129" ry="193.129"/><ellipse class="h" cx="193.129" cy="193.129" rx="192.629" ry="192.629"/></g></g></g></svg>
Upvotes: 0
Views: 184
Reputation: 101820
Adjust your viewBox
size so it is slightly smaller than the grey square. At the moment rounding and pixel alignment, together with anti-aliasing bleed-through, means the blue JPEG underneath is slightly visible on the edges. By shrinking the viewBox, we are effectively making the grey square a fraction bigger, hiding the bleed-through.
width="512" height="513"
attributes.Result:
.container {
background-color: #f7f7f7;
height: 1000px;
padding: 20px;
}
.media {
position: relative;
max-height: 408px;
height: 155px;
width: 200px;
margin: 0 auto;
}
.media img {
max-width: 100%;
height: 100%;
object-fit: cover;
}
.media::before{
content: "";
background-image: url(https://svgshare.com/i/HPM.svg);
position: absolute;
background-position: center center;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 10;
background-size: cover;
background-repeat: no-repeat;
}
<div class="container">
<div class="media">
<img src="https://i.imgur.com/iD4ERTU.jpg">
</div>
</div>
Upvotes: 2