Issue
I'm using multiple containers so I can have unique transparent image in them.
I want the background image in them to be responsive and to keep ratio, I found a lot of suggestions to put background-size: cover;
but it doesn't work for me. I can't get the image to be responsive.
what I've tried:
object-fit: contain;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
flex: 1;
css code:
.container{
display: block;
position: relative;
}
.container1::after {
content: "";
background: url(bg2.jpg);
background-repeat:no-repeat;
background-position: center center;
opacity: 0.3;
top: 0;
left: 0;
bottom: 0;
right: 0;
position: absolute;
z-index: -1;
object-fit: contain;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
flex: 1;
}
html:
<div class="container container1">
<p> some text </p>
</div>
Solution
If you want the same image to scale based on the size of the browser window then here is the code.
background-image:url('../images/bg.png');
background-repeat:no-repeat;
background-size:contain;
background-position:center;
Do not set width, height, or margins.
Answered By - Thanveer Shah
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.