Reputation: 4811
I am trying to place a DIV block on the top corner of an image that can hold multiple lines of text. Managed to make a overlay on corner of image like below
.sliderImgWrapper {
position: relative;
width: 200px;
height: 300px;
border: 2px solid #000000;
}
.overlay {
position: absolute;
top: 0px;
left: 0px;
border-top: 50px solid #FF0000;
border-right: 50px solid transparent;
}
.overlayImage {
position: absolute;
top: -50px;
left: -25px;
}
<div class="sliderImgWrapper">
<div class="overlay">
</div>
</div>
But not sure how can I make the transparency of the image to a light shade on one side of the div. A similar or closer look is like in the image
Also after placing a span to hold text inside the red area like
<div class="overlay">
<span style="color:blue;">title</span>
</div>
The triangular shape seems to be broken
Upvotes: 2
Views: 85
Reputation: 61056
You can do this without additional markup using pseudo-elements.
.sliderImgWrapper {
position: relative;
width: 200px;
height: 300px;
border: 2px solid #000000;
background-image: url("https://i.sstatic.net/vNFzE.png");
background-size: cover;
}
.sliderImgWrapper:before,
.sliderImgWrapper:after {
content: '';
position: absolute;
top: 0px;
left: 0px;
border-top: 120px solid #FF0000;
}
.sliderImgWrapper:before {
border-right: 180px solid transparent;
opacity: 0.5;
}
.sliderImgWrapper:after {
border-right: 150px solid transparent;
}
.sliderImgWrapper span {
position: absolute;
top: 10px;
left: 10px;
display: inline-block;
color: white;
font-size: 10px;
border-bottom: 1px solid white;
z-index: 1;
}
<div class="sliderImgWrapper">
<span>UNIVERSITY<br>UNIVERSITY<br>UNIVERSITY</span>
</div>
Upvotes: 4