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.

Element styling only for html2canvas?

See original GitHub issue

I’m using the handy data-html2canvas-ignore tag on a few elements, but Firefox is giving me problems with elements with negative margins. I’d like to be able to add an html2canvas-only style tag for a particular element, such as: data-html2canvas-style="margin-left: 0".

Has anyone else had any luck doing something like this?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

16reactions
niklasvhcommented, Oct 19, 2015

You can modify the contents of the document (which is a clone of the original) that will get rendered with the onclone option, for example:

html2canvas(document.body, {onclone: function(document) {
  document.querySelector('.something').style.marginLeft = 0;
}}).then(...)
2reactions
akyenzecommented, Jun 27, 2019

I tried to do the same thing, here is how I implemented it and all my styles were properly downloaded:

const computedStyleToInlineStyle = require("computed-style-to-inline-style");

 html2canvas(document.querySelector(".someclass"), {onclone: function(document) {
     computedStyleToInlineStyle(document.querySelector(".someclass"), {
          recursive: true
      });
    }}).then(canvas => {
        const imgData = canvas.toDataURL('image/png');
        ...
    });
Read more comments on GitHub >

github_iconTop Results From Across the Web

Features - html2canvas
Below is a list of all the supported CSS properties and values. ... text-decoration-color; text-decoration-line; text-decoration-style (Only supports solid ).
Read more >
how to apply css only to the generated canvas in html2canvas
For the former, apply the styles before exporting, export, then remove the styles. For the later, just add some className to the element...
Read more >
jsPDF Html2Canvas Tutorial to Export HTML With ... - YouTube
... of application here:https://webninjadeveloper.com/javascript/jspdf- html2canvas -tutorial-to-export-html-with-custom- css - styles -to-pdf...
Read more >
html-to-image css grid styling not working properly on latest ...
Oops, it looks like html2canvas.js isn't actually used at all in the original jsfiddle testcase. (It's referenced but unused.) html-to-image.js is the only...
Read more >
Export React components as images using html2canvas
html2canvas reads a webpage as a canvas image. It goes through the webpage's DOM and reads all present elements and styles. After html2canvas...
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