Issue
I need a Lightbox with a responsive image that has a close button in the top right corner of the image.
This works only in Safari:
* {
box-sizing: border-box;
}
.lightbox {
position: fixed;
left: 0;
top: 0;
width: 100vw;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
padding: 50px;
background: rgba(0 0 0 / 0.9);
}
.inner {
position: relative;
height: fit-content;
}
img {
display: block;
max-width: 100%;
max-height: 100%;
}
button {
position: absolute;
right: 0;
top: 0;
}
<div class="lightbox">
<div class="inner">
<img src="https://fakeimg.pl/1600x900" />
<button></button>
</div>
</div>
But in Chrome and Firefox the height: fit-content
of .inner
doesn't work.
Here is a video demonstration.
Solution
* {
box-sizing: border-box;
}
.lightbox {
position: fixed;
left: 0;
top: 0;
width: 100vw;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
padding: 50px;
background: rgba(0 0 0 / 0.9);
}
.inner {
position: relative;
height: fit-content;
}
img {
display: block;
max-width: 100%;
max-height: 100vh;
object-fit: cover;
object-position: center;
}
button {
position: absolute;
right: 0;
top: 0;
}
<div class="lightbox">
<div class="inner">
<img src="https://fakeimg.pl/1600x900" />
<button></button>
</div>
</div>
You can use "100vh" instead of "100%" it will help
Answered By - ertuozdenli
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.