确定 HTML 文本的字体和大小
我需要确定每个 HTML 元素将使用什么字体和大小。它们可以在各种 css、div、span 或元素本身上设置。
如果我要手动执行此操作,我会首先查看元素并向后工作,直到找到具有字体和/或大小的 span、div 或 css。这就是我想要的价值。浏览器显然可以做到这一点,因为它使用字体和大小显示文本。我想打印一个包含两列的列表,一列包含文本,另一列包含字体/大小。
I need to determine what font and size will be used for each HTML element. They may be set in various css, div, span, or on the element itself.
If I were to do this manually I would start by looking at the element and work backwards until I came to span, div, or css that had a font and/or size. That is the value I want. The browser can obviously do this because it displays the text using a font and size. I want to print a list with two columns, one with the text and the other with the font/size.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您正在寻找非编程方式:我建议使用 firebug 插件< /a> 对于 Mozilla。 Firebug 不仅会向您显示所有属性,还允许您在客户端中打开和关闭它们。
If you are looking for a non-programmatic way: I would suggest the firebug plugin for mozilla. Firebug will not only show you all attributes, but allow you to turn them on and off in the client.
您想要重现将 HTML 解析为 DOM 对象、将 CSS 解析为这些对象的规则以及在对象之间应用这些规则以最终得到关联的compatedStyle 值的功能吗?对我来说,这听起来很像一个网络浏览器。
您可以尝试编写 Firefox 或 IE WebBrowser 控件的脚本。还有一个正在开发的 开源原生 Java 浏览器/工具包,尽管我不知道实用性如何那是还没有。
You want to reproduce the functionality of parsing HTML into DOM objects, parsing CSS into rules over those objects, and applying those rules across the objects to end up with the associated computedStyle values? That sounds pretty much like a web browser to me.
You could try scripting Firefox or an IE WebBrowser control. There's also an open-source native Java browser/toolkit being developed, though I don't know how practical that is yet.