vue使用html2Canvas导出图片 input文字向上偏移

vue使用html2Canvas导出图片 input文字向上偏移

图中 用的是element的输入框 行高 32px,经常测试 你使用原生的input 还是会出现偏移。

解决方法:修改css样式

1.怎么实现导出 网上随便找很多

2.在第一步 获取你要导出的元素id 克隆后 修改他的样式或者 你直接在你需要打印的页面全局修改样式

3.主要是重置字体的行高,我这里输入框高度是32px 固定的 ,那就使用line-height 和 padding-top 来让他文字居中

复制代码
const cloneDom = document.getElementById(content).cloneNode(true)
        document.getElementsByTagName('body')[0].appendChild(cloneDom)
        cloneDom.querySelectorAll('input').forEach(input => {
          input.style.height = '32px'
          input.style.lineHeight = '14px'
          input.style.paddingTop = '6px'
        })

效果 差不多 能居中了 完美解决

相关推荐
yuanyxh7 小时前
Mac 软件推荐
前端·javascript·程序员
万少7 小时前
AtomCode开发微信小程序《谁去呀》 全流程
前端·javascript·后端
某人辛木7 小时前
Web自动化测试
前端·python·pycharm·pytest
Kagol8 小时前
Superpowers GSD gstack AgentSkills深度测评
前端·人工智能
excel9 小时前
JavaScript 字符串与模板字面量:从表象到本质理解
前端
京东云开发者9 小时前
当AI成为导演-如何用AI创作动漫短剧
前端
李白的天不白9 小时前
使用 SmartAdmin 进行前后端开发
java·前端
乘风gg10 小时前
🤡PUA AI Coding 工具 的 10 条终极语录
前端·ai编程·claude
学Linux的语莫10 小时前
Vue 3 入门教程
前端·javascript·vue.js
怕浪猫10 小时前
第一章、Chrome DevTools Protocol (CDP) 详解
前端·javascript·chrome