关于调试打印样式表的建议?

发布于 2024-08-25 11:01:32 字数 352 浏览 6 评论 0原文

我最近一直在为一个网站制作打印样式表,我意识到我不知道如何有效地调整它。在屏幕布局上工作有一个重新加载周期是一回事:

  • 更改代码
  • 命令选项卡
  • 重新加载

,但是当您尝试打印时,整个过程会变得更加艰巨:

  • 更改代码
  • 命令选项卡
  • 重新加载
  • 打印
  • 在打印时眯眼-预览图像
  • 在预览中打开 PDF 进行进一步检查

我是否遗漏了哪些工具? WebKit 的检查器是否有“假装这是分页媒体”复选框? Firebug (shudder) 有什么魔法吗?

I've recently been working on a print stylesheet for a website, and I realized that I was at a loss for effective ways to tweak it. It's one thing to have a reload cycle for working on the on-screen layout:

  • change code
  • command-tab
  • reload

but that whole process gets much more arduous when you're trying to print:

  • change code
  • command-tab
  • reload
  • print
  • squint at print-preview image
  • open PDF in Preview for further inspection

Are there tools I'm missing out on here? Does WebKit's inspector have a "pretend this is paged media" checkbox? Is there some magic that Firebug (shudder) can do?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(13

浅暮の光 2024-09-01 11:01:32

Chrome 的检查器中有一个选项。

  1. 打开 DevTools 检查器(mac:Cmd + Shift + C,windows:Ctrl + Shift< /kbd> + C)
  2. 单击切换设备模式图标
  3. 单击浏览器视口右上角的更多覆盖 more overrides 图标打开开发工具抽屉。
  4. 然后,在模拟抽屉中选择媒体,并选中CSS媒体复选框。

    在此处输入图像描述

这应该可以解决问题。

更新:DevTools 中的菜单已更改。
现在可以通过点击右上角的“三点”菜单> >找到它。更多工具>>渲染设置>模拟媒体>打印。

来源:Google DevTools 页面*

There is an option for that in Chrome's inspector.

  1. Open the DevTools inspector (mac: Cmd + Shift + C , windows: Ctrl + Shift + C)
  2. Click on the Toggle device mode icon Toggle device mode button, located on the upper left corner of the DevTools panel. (windows: Ctrl+Shift+M, mac: Cmd+Shift+M).
  3. Click on the More overrides more overrides icon in the top right corner of the browser viewport to open the devtools drawer.
  4. Then, select Media in the emulation drawer, and check the CSS media checkbox.

    enter image description here

This should do the trick.

Update: The menus have changed in DevTools.
It can now be found by clicking on the "three-dots" menu in the top right corner > More Tools > Rendering Settings > Emulate media > print.

Source: Google DevTools page*

记忆で 2024-09-01 11:01:32

我假设您希望在不使用 HTML 到 PDF 方法的情况下尽可能多地控制打印窗口...使用 @media screen 进行调试 - @media print for Final css

现代浏览器可以让您快速了解将要发生的情况在打印时在 @media 查询 中使用 英寸 发生。

@media screen and (max-width:8.5in) { /* resize your window until the event is triggered */
    html { width:8.5in; }
    body { font: 9pt/1.5 Arial, sans-serif; } /* Roughly 12px font */
 ...
}

一旦您的浏览器显示“英寸”,您就会更好地了解会发生什么。这种方法应该可以结束打印预览方法。所有打印机都可以使用 ptin 单位,并且使用 @media 技术将允许您快速查看将要发生的情况并进行相应调整。 Firebug(或同等产品)绝对会加快这个过程。当您将更改添加到 @media 后,您就获得了使用 media = "print" 属性链接 CSS 文件所需的所有代码 - 只需将 @media 屏幕规则复制/粘贴到引用的文件。

祝你好运。网络不是为打印而构建的。创建一个解决方案来提供与浏览器中看到的内容相同的所有内容、样式有时是不可能的。例如,主要面向 1280 x 1024 受众的流畅布局并不总是能轻松转化为美观整洁的 8.5 x 11 激光打印。

purusal 的 W3C 参考:http://www.w3.org/TR/css3-mediaqueries/< /a>

I'm assuming you want as much control of the printed window as possible without using a HTML to PDF approach... Use @media screen to debug - @media print for final css

Modern browsers can give you a quick visual for what's going to happen at print time using inches and pts in a @media query.

@media screen and (max-width:8.5in) { /* resize your window until the event is triggered */
    html { width:8.5in; }
    body { font: 9pt/1.5 Arial, sans-serif; } /* Roughly 12px font */
 ...
}

Once your browser is displaying "inches" you'll have a better idea of what to expect. This approach should all but end the print preview method. All printers will work with pt and in units, and using the @media technique will allow you to quickly see what's going to happen and adjust accordingly. Firebug (or equivalent) will absolutely expedite that process. When you've added your changes to @media, you've got all the code you need for a linked CSS file using media = "print" attribute - just copy/paste the @media screen rules to the referenced file.

Good luck. The web wasn't built for print. Creating a solution that delivers all of your content, styles equal to what's seen in the browser can be impossible at times. For instance, a fluid layout for a predominantly 1280 x 1024 audience doesn't always translate easily to a nice and neat 8.5 x 11 laser print.

W3C reference for purusal: http://www.w3.org/TR/css3-mediaqueries/

离笑几人歌 2024-09-01 11:01:32

Chrome 48 您可以在渲染选项卡中调试打印样式。

单击检查器右上角的菜单图标和渲染设置

编辑
对于 Chrome 58,位置已更改为 Web Inspector >菜单>更多工具>>渲染

Chrome 48 you can debug print styles within the Rendering tab.

Click the menu icon top right of inspector and Rendering Settings.

Edit
For Chrome 58 the location has changed to Web Inspector > Menu > More Tools > Rendering

静待花开 2024-09-01 11:01:32

在 Chrome v41 中,它就在那里,但位置略有不同。

在此处输入图像描述

In Chrome v41, it's there, but in a slightly different spot.

enter image description here

奶茶白久 2024-09-01 11:01:32

有一种简单的方法可以调试打印样式表,而无需切换 HTML 代码中的任何媒体属性(当然,正如所指出的,它不能解决宽度/页面问题):

  • 使用 Firefox + Web Developer 扩展。
  • 在 Web 开发人员菜单中,选择 CSS / 按媒体类型显示 CSS / 打印
  • 返回到 Web 开发人员菜单,选择选项 / 保留功能

现在您正在查看打印 CSS,并且可以无限期地重新加载页面。
完成后,取消选中“持久功能”并重新加载,您将再次获得屏幕 CSS。

HTH。

There's an easy way to debug your print stylesheet without switching any media attribute in your HTML code (of course, as pointed out, it doesn't solve the width / pages issue):

  • Use Firefox + Web Developer extension.
  • In the Web Developer menu, choose CSS / Display CSS by Media Type / Print
  • Go back to Web Developer menu, choose Options / Persist Features

Now you are viewing the print CSS and you can reload your page indefinitely.
Once you're done, uncheck "Persist Features" and reload, you'll get the screen CSS again.

HTH.

耶耶耶 2024-09-01 11:01:32

从 v53 开始,Chrome 的用户界面再次有所不同。

我不需要经常使用这个功能,但每当我使用时,我都会花很长时间才能弄清楚自上次我刻录周期试图追踪它以来 Chrome 团队已将其移至何处。

请注意,这是开发工具窗格中的...菜单而不是Chrome浏览器窗格中的...菜单。

打印机预览为MacOS 上的 v53

现在在渲染部分向下滚动。它通常位于首屏下方。

Chrome's UI is different again as of v53.

I don't need to use this feature often, but whenever I do, it takes me forever to figure out where the Chrome team has moved it since the last time I burned cycles trying to track it down.

Notice it's the ... menu in Dev Tools pane not the ... menu in Chrome Browser pane.

Printer preview as of v53 on MacOS

Now scroll down in the Rendering section. It's often below the fold.

草莓味的萝莉 2024-09-01 11:01:32

根据 rflnogueira 的回答,当前的 Chrome 设置 (40.0.*) 如下所示:

chrome print css emulation

Following up to the answer by rflnogueira, the current Chrome settings (40.0.*) will look like below:

chrome print css emulation

一江春梦 2024-09-01 11:01:32

只需在调试时使用 media="screen" 在浏览器中显示打印样式表即可。打印预览视图使用与正常浏览模式相同的渲染引擎,因此您可以使用它获得准确的结果。

Just show the print stylesheet in your browser using media="screen" while debugging. The print preview view uses the same rendering engine as normal browsing mode so you can get accurate results using that.

末が日狂欢 2024-09-01 11:01:32

2019 - 更新说明

  1. 打开 Chrome 检查器
    • 来自Mac => 选项 + 命令 + i
    • 来自Windows => F12
  2. 点击小3点,自定义和控制devTools 在此处输入图像描述

  3. 选择更多工具

  4. 选择渲染

  5. 滚动到底部模拟CSS媒体

  6. 从向下箭头选择打印

在此处输入图像描述

2019 - Updated instructions

  1. Open Chrome inspector
    • From Mac => option + command + i
    • From Windows => F12
  2. Click on the little 3 dots, customize and control devTools enter image description here

  3. Select More Tools

  4. Select Rendering

  5. Scroll to the bottom to Emulate CSS Media

  6. Select print from the down arrow

enter image description here

初懵 2024-09-01 11:01:32

如果您有一个打印函数,可以将页面内容重写到一个新窗口并引用您的打印样式表,您将更好地了解它在纸上的样子,并且您将能够对其进行调试也有像萤火虫这样的人。

这是如何使用 JavaScript / jquery 完成此操作的示例

        $("#Print").click(function () {
            var a = window.open('', '', 'scrollbars=yes,width=1024,height=768');
            a.document.open("text/html");
            a.document.write("<html><head>");
            a.document.write('<link rel="stylesheet" href="css/style.css" />');
            a.document.write('<link rel="stylesheet" href="css/print.css" />');
            a.document.write("</head><body>");
            a.document.write($('#Content').html());
            a.document.write('</body></html>');
            a.document.close();
            a.print();
        });

If you have a print function that rewrites the content of the page to a new window with your print style sheet referenced you'll get a much better idea of what its going to look like on paper , and you'll be able to debug it with the likes of firebug too.

Heres an example of how this can be done with JavaScript / jquery

        $("#Print").click(function () {
            var a = window.open('', '', 'scrollbars=yes,width=1024,height=768');
            a.document.open("text/html");
            a.document.write("<html><head>");
            a.document.write('<link rel="stylesheet" href="css/style.css" />');
            a.document.write('<link rel="stylesheet" href="css/print.css" />');
            a.document.write("</head><body>");
            a.document.write($('#Content').html());
            a.document.write('</body></html>');
            a.document.close();
            a.print();
        });
并安 2024-09-01 11:01:32

在 Firefox (87.0) 中,“DOM 和样式检查器”有一个用于打印媒体模拟的切换按钮。

输入图片这里的描述

一个缺点是它没有清楚地划定页面边界。

In Firefox (87.0), the "DOM and Style Inspector" has a toggle button for print media simulation.

enter image description here

One drawback is that it does not clearly delineate the page boundaries.

情话已封尘 2024-09-01 11:01:32

在此处输入图像描述

在 DreamWeaver 中,有一个工具栏,几乎可以显示您想要的任何渲染选项:
屏幕、印刷品、手持媒体、投影屏幕、电视媒体、设计时间样式表等。
我之所以使用它,主要是因为它:只需按一下按钮即可立即显示预览。

enter image description here

In DreamWeaver there is a toolbar that shows virtually any rendering option you want:
screen, print, handheld media, projection screen, tv media, desitn time style sheets, etc.
This is what I use especially because it: instantly shows a preview with 1 single press of a button.

帅冕 2024-09-01 11:01:32

我使用宏来重复发送按键和鼠标点击。
在 Windows 下,AutoHotKey 是一个很棒的软件,在 OS X 下,您可以阅读有关 Automator 的信息,它是一种替代 AHK 的信息OSX

在 Windows 下(在 OS X 下将 Ctrl 替换为 Cmd)“Ctrl-s / 切换到 Fx 窗口,无论它在打开的窗口列表中/Ctrl-r”绑定到 1 个未使用的键,避免了无趣任务的挫败感,最终将拯救我的手臂来自 RSI :)

I use macros to send keypress and mouse clicks repeatedly.
Under Windows, AutoHotKey is a great software and under OS X you can read about Automator sort of an alternative AHK for OsX.

Under Windows (replace Ctrl by Cmd under OS X) "Ctrl-s / switch to Fx window wherever it is in the list of windows opened / Ctrl-r" bound to 1 unused key avoids frustration from uninteresting tasks and will ultimately save my arms from RSI :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文