Skip to content

Instantly share code, notes, and snippets.

@UncleKo
Created November 8, 2021 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save UncleKo/ef9a7832f8c7a96fc614fdff304555f2 to your computer and use it in GitHub Desktop.
Save UncleKo/ef9a7832f8c7a96fc614fdff304555f2 to your computer and use it in GitHub Desktop.
Image Contain Methods
1. Background Image
<div style="background-image: url('{{ item.image_medium.url }}');"></div>
div {
width: 100%;
height: 100%;
background-size: contain;
background-position: center center;
background-repeat: no-repeat;
}
2. Object Contain
<img src="{{ item.image_medium.url }}" class="" alt="">
img {
width: 100%;
height: 100%;
object-fit: contain;
}
3. Flexbox
<a><img src="{{ item.image_medium.url }}" class="" alt=""></a>
a {
height: 100%;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
}
img {
width: auto;
max-height: 100%;
max-width: 100%;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment