关于调试打印样式表的建议?
我最近一直在为一个网站制作打印样式表,我意识到我不知道如何有效地调整它。在屏幕布局上工作有一个重新加载周期是一回事:
- 更改代码
- 命令选项卡
- 重新加载
,但是当您尝试打印时,整个过程会变得更加艰巨:
- 更改代码
- 命令选项卡
- 重新加载
- 打印
- 在打印时眯眼-预览图像
- 在预览中打开 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
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(13)
Chrome 的检查器中有一个选项。
然后,在模拟抽屉中选择媒体,并选中CSS媒体复选框。
这应该可以解决问题。
更新:DevTools 中的菜单已更改。
现在可以通过点击右上角的“三点”菜单> >找到它。更多工具>>渲染设置>模拟媒体>打印。
来源:Google DevTools 页面*
There is an option for that in Chrome's inspector.
Then, select Media in the emulation drawer, and check the CSS media checkbox.
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*
我假设您希望在不使用 HTML 到 PDF 方法的情况下尽可能多地控制打印窗口...使用 @media screen 进行调试 - @media print for Final css
现代浏览器可以让您快速了解将要发生的情况在打印时在
@media 查询
中使用 英寸 和 磅 发生。一旦您的浏览器显示“英寸”,您就会更好地了解会发生什么。这种方法应该可以结束打印预览方法。所有打印机都可以使用
pt
和in
单位,并且使用 @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
.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
andin
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 usingmedia = "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/
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
在 Chrome v41 中,它就在那里,但位置略有不同。
In Chrome v41, it's there, but in a slightly different spot.
有一种简单的方法可以调试打印样式表,而无需切换 HTML 代码中的任何媒体属性(当然,正如所指出的,它不能解决宽度/页面问题):
现在您正在查看打印 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):
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.
从 v53 开始,Chrome 的用户界面再次有所不同。
我不需要经常使用这个功能,但每当我使用时,我都会花很长时间才能弄清楚自上次我刻录周期试图追踪它以来 Chrome 团队已将其移至何处。
请注意,这是开发工具窗格中的...菜单而不是Chrome浏览器窗格中的...菜单。
现在在渲染部分向下滚动。它通常位于首屏下方。
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.
Now scroll down in the Rendering section. It's often below the fold.
根据 rflnogueira 的回答,当前的 Chrome 设置 (40.0.*) 如下所示:
Following up to the answer by rflnogueira, the current Chrome settings (40.0.*) will look like below:
只需在调试时使用
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.2019 - 更新说明
选项
+命令
+i
F12
点击小3点,
自定义和控制devTools
选择
更多工具
选择
渲染
滚动到底部
模拟CSS媒体
从向下箭头选择
打印
2019 - Updated instructions
option
+command
+i
F12
Click on the little 3 dots,
customize and control devTools
Select
More Tools
Select
Rendering
Scroll to the bottom to
Emulate CSS Media
Select
print
from the down arrow如果您有一个打印函数,可以将页面内容重写到一个新窗口并引用您的打印样式表,您将更好地了解它在纸上的样子,并且您将能够对其进行调试也有像萤火虫这样的人。
这是如何使用 JavaScript / jquery 完成此操作的示例
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
在 Firefox (87.0) 中,“DOM 和样式检查器”有一个用于打印媒体模拟的切换按钮。
一个缺点是它没有清楚地划定页面边界。
In Firefox (87.0), the "DOM and Style Inspector" has a toggle button for print media simulation.
One drawback is that it does not clearly delineate the page boundaries.
在 DreamWeaver 中,有一个工具栏,几乎可以显示您想要的任何渲染选项:
屏幕、印刷品、手持媒体、投影屏幕、电视媒体、设计时间样式表等。
我之所以使用它,主要是因为它:只需按一下按钮即可立即显示预览。
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.
我使用宏来重复发送按键和鼠标点击。
在 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 :)