question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Canvas ignores object-fit property

See original GitHub issue

When using any object-fit setting, its being ignored and images are simply stretched to fill the space due to flexbox props.

.bt-create-post-images-container {
  min-width: 100%;
  background-color: #8f8f8f;
  height: 350px;
  overflow: hidden;
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
}

.bt-create-post-image-container {
  background-color: #8f8f8f;
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
}

.bt-create-post-image-container > img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  align-self: auto;
  vertical-align: middle;
}
<div class="bt-create-post-images-container" id="images">
  <div class="bt-create-post-image-container {{type == 'versus' && 'flex-versus' || ''}}">
    <img ng-show="show_left" ng-src="{{uri_left}}">
  </div>
  <div class="bt-create-post-image-container {{type == 'versus' && 'flex-versus' || ''}}">
    <img ng-show="show_right" ng-src="{{uri_right}}">
  </div>
</div>

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:6
  • Comments:14

github_iconTop GitHub Comments

7reactions
jpyamamotocommented, Mar 6, 2018

Are there updates regarding this issue? Has anyone found a workaround?

6reactions
logicalicycommented, Dec 27, 2020

FYI, there’s a different solution/workaround, as I struggled with object-fit and object-position. Instead of using an img, use a div with following CSS:

background-image: url(<MY_SOURCE>);
background-size: <OBJECT_FIT>;
background-position: <OBJECT_POSITION>;
Read more comments on GitHub >

github_iconTop Results From Across the Web

Html2canvas Ignores Object fit for image - Stack Overflow
I noticed an image inside the div element that uses the object-fit property becomes stretched after the html2canvas screenshot.
Read more >
object-fit - CSS: Cascading Style Sheets - MDN Web Docs
The object-fit CSS property sets how the content of a replaced element, such as an or , should be resized to fit its...
Read more >
Object Fit - Tailwind CSS
Using an element's original size. Display an element's content at its original size ignoring the container size using .object-none .
Read more >
The canvas state - HTML Standard, Edition for Web Developers
A canvas element can be sized arbitrarily by a style sheet, its bitmap is then subject to the 'object-fit' CSS property.
Read more >
Embedded Content — SVG 2
The object-fit and object-position affect the final position and size of the ... attribute on the root element in the referenced SVG image...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found