MS Word复制文本来自HTML PRE元素,其内部元素具有font-family设置为继承的,导致font-fominy not far by by by corcrecty设置

发布于 2025-02-03 10:05:36 字数 1306 浏览 2 评论 0原文

我遇到了这个问题,在将pre> pre标记中的文本复制到Microsoft Word中时,将复制的字体家庭设置为第一个计算的font for for该元素。例如,如果*具有font-family:sashit文本复制的字体 - 家庭将设置为Microsoft Word中的sashit没有其他字体家庭直接为该对象设置。

如果使用Div更改了PRE> PRE标签,则不会发生此问题,但这在我的情况下是不可能的。

是否有人知道一种修复此操作的方法,以使正确的字体复制,在该字体中仍​​将字体家庭应用于pre> pre元素。

演示代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="test.css">
    <title>Document</title>
</head>
<body>
    <pre><code><span>This is text</span></code></pre>
</body>
</html>

test.css

*{
    font-family: inherit;
}

pre {   
    font-family: Verdana,Helvetica,Arial,sans-serif;
}

“跨元素的字体家庭外观的示例”

I am having this problem where when copying text from within a pre tag into microsoft word, the font-family being copied is set to the first computed font-family for the element. For example if * has font-family: inherit the copied font-family for the text would be set to inherit in microsoft word, if there is no other font-family set directly for that object.

This problem does not occur if the pre tag is changed out with a div, but this is not possible in my case.

Does anybody know a way to fix this such that the correct font is copied, where the font-family is still being applied to the pre element.

Demo code

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="test.css">
    <title>Document</title>
</head>
<body>
    <pre><code><span>This is text</span></code></pre>
</body>
</html>

test.css

*{
    font-family: inherit;
}

pre {   
    font-family: Verdana,Helvetica,Arial,sans-serif;
}

Example of what the font-family look like for span element

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文