Skip to content

Instantly share code, notes, and snippets.

@mwolson
Created March 20, 2019 23:31
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 mwolson/69b3b044aa4a0b0377211762da73e28c to your computer and use it in GitHub Desktop.
Save mwolson/69b3b044aa4a0b0377211762da73e28c to your computer and use it in GitHub Desktop.
zoom image into a box preserving aspect ratio
.tc-ConversationItem[class] .tc-ConversationItem__avatar .tc-AvatarImage {
// modify these with something like calc(200%), or manual width/height "box" around the image
// which then gets zoomed to fit
width: 52px;
height: 52px;
}
.tc-AvatarImage[class].tc-AvatarImage--size--fit {
display: block;
width: 100%;
height: 100%;
max-width: 100%;
max-height: 100%;
}
.tc-AvatarImage[class] {
position: relative;
display: inline-block;
vertical-align: middle;
line-height: 1; // possibly remove
}
.tc-AvatarImage[class] .tc-AvatarImage__image-container-square {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
width: 100%;
height: 100%;
background-position: center center;
background-size: cover;
overflow: hidden;
}
.tc-AvatarImage[class] .tc-AvatarImage__image-container-square > * {
min-width: 100%;
max-width: 100%;
min-height: 100%;
max-height: 100%;
-o-object-fit: cover;
object-fit: cover;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
pointer-events: auto;
}
.tc-AvatarImage[class] .tc-AvatarImage__image-container-square * {
// there's some kind of min-height bug with IE 11 which requires this
height: 10px;
}
<!-- possibly use div instead of span since this example sits inside of a row -->
<span class="tc-UserAvatar tc-AvatarImage tc-AvatarImage--size--fit tc-AvatarImage--user" title="QA Mike Olson 2">
<div class="tc-AvatarImage__image-container-square" style="background-image: url(&quot;https://some-image/1.jpg&quot;);">
<img src="https://some-image/1.jpg" alt="QA Mike Olson 2" class="tc-AvatarImage__image">
</div>
</span>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment