Text on an image with vignette effect CSS
I am trying to create a page banner which is an image with text over it. There are two things I am facing trouble with two things.
-
I need a smooth vignette effect on these images so that the text is clearly visible. I have tried the following but am not happy with the end result. I would like to get something as shown in the following image which shows a kind of smooth transition.
-
The text hides below the vignette effect. I tried using
z-index
but it does not work.
body {
margin: 0px;
}
#page-banner img {
width: 100%;
object-fit: cover;
height: 48vh;
}
#page-banner .vignette:after {
content: '';
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
width: 100%;
height: 100%;
-webkit-box-shadow: inset 20em 5em 15em black;
-moz-box-shadow: inset 20em 5em 15em black;
box-shadow: inset 20em 5em 15em black;
z-index: 0;
}
#page-banner .text {
width: 50%;
right: 50%;
z-index: 1;
}
#page-banner .text-over-image {
position: relative;
}
#page-banner .text-over-image p {
font-size: 60px;
color: white;
margin: 0;
position: absolute;
top: 50%;
left: 15%;
right: 45%;
transform: translate(-10%, -50%);
}
<section id="page-banner">
<div class="text-over-image vignette">
<img src="https://wallpaperaccess.com/full/5117570.jpg">
<div class="text">
<p>I am trying to learn adding vignette to images</p>
</div>
</div>
</section>
Comments
Post a Comment