I was trying to create a text overlay on top of an image, and I wanted to add a slight border-radius to it all. But I noticed that when adding border-radius: 5px and overflow: hidden to the parent, the image behind the overlay is still showing a small part of its border on the bottom corners, as if it forgot to hide a pixelated line there.
(small grey line in bottom right corner from image still visible)
.main-info {
box-shadow: 0px 0px 3px 2px #221b25c7;
border-radius: 5px;
font-size: 0.75rem;
overflow: hidden;
}
.main-info > .img {
position: relative;
}
.text {
position: absolute;
display: flex;
width: 100%;
bottom: 0;
-webkit-box-align: center;
align-items: center;
-webkit-box-pack: justify;
justify-content: space-between;
-webkit-transition: opacity 0.2s ease-out;
transition: opacity 0.2s ease-out;
opacity: 1;
color: white;
background-color: rgba(0, 0, 0, 0.65);
backdrop-filter: blur(3px);
z-index: 5;
line-height: 25px;
}
.text > .limit {
color: white;
-webkit-box-flex: 1;
-ms-flex: 1;
flex: 1;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
position: relative;
max-width: 100%;
width: 0;
padding: 0 0.5rem;
}
.text > .limit {
text-align: center;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<div class="row m-5">
<div class="col-8">
<div class="main-info">
<div class="img">
<a href="#">
<div class="text">
<div class="limit">Hello World</div>
</div>
<img src="https://placehold.it/272x154" style="width: 100%">
</a>
</div>
</div>
</div>
</div>
I've thought of just adding the border-radius to the children, but that gave the same result.
I've actually found this gist yesterday, which seems like a miracle fix for the border issue on the overflow item:
-webkit-mask-image: -webkit-radial-gradient(white, black);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With