Skip to content

Instantly share code, notes, and snippets.

@namncn
Last active October 12, 2020 03:32
Show Gist options
  • Save namncn/3dd03b42d0e0c2d6c7a952c61cb402a5 to your computer and use it in GitHub Desktop.
Save namncn/3dd03b42d0e0c2d6c7a952c61cb402a5 to your computer and use it in GitHub Desktop.
<div class="post-thumb">
<img src="https://i.imgur.com/iCMEVjr.jpg" alt="Norway">
</div>
.post-thumb {
position: relative;
height:0;
padding-bottom: 56.25%; // Điền % bạn cần.
}
// Ảnh tràn khung.
.post-thumb img {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
object-fit: cover;
}
//Ảnh lọt chính giữa khung
.post-thumb img {
position: absolute;
top: 50%;
left: 50%;
width: 100%;
height: 100%;
object-fit: contain;
transform: translate(-50%, -50%);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment