在 C# 中使用 MSHTML 获取当前样式
我想使用 MSHTML 来获取 html 元素的样式。
我想要的是计算的样式,但没有所有默认值。 (只有在html和css中设置的)
MSHTML有3种类型的样式,我到目前为止见过style,currentStyle和runtimeStyle。
style 和 runtimeStyle 仅具有内联样式,而当前 Style 具有包括继承样式和默认样式在内的所有内容。
有没有办法获取当前设置的样式(内联,外部和内部CSS)但没有所有继承和默认值?
必须有一种方法可以做到这一点,IE 开发人员工具栏似乎知道哪些样式是从哪里继承的。
I want to use MSHTML to get the style of an html element.
What I want is the computed style but without all the default values. (only the ones that are set in the html and css)
MSHTML has 3 types of styles that I have seen so far style, currentStyle, and runtimeStyle.
style and runtimeStyle only has the inline styles and current Style has everything including inherited and default styles.
Is there a way to get the currently set style (inline, external and internal css) but without all the inherited and default values?
There has got to be a way to do this, the IE developer toolbar seems to know which styles are inherited from where.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您说要排除“默认”和/或继承属性时,而不是内联、外部和内部 css,这并不是完全正确的措辞,因为默认属性是通过用户代理 css 设置的。
我想象一种从显式应用的属性中过滤“默认”属性的方法是在运行时比较使用 css/内联样式在页面上呈现的元素与在没有外部 CSS 的情况下在相同 DOM 结构中呈现的相同元素内联样式被剥离;也许在隐藏的 iframe 等中。这有意义吗?
根据您的舒适程度,您可能会幸运地查看 Firebug Lite 源。
When you say you want to exclude "default" and/or inherited properties as opposed to inline, external and internal css that is not entirely correct phrasing since default properties are set through user-agent css.
I'd imagine one way to filter "default" properties from explicitly applied ones would be to compare at runtime an element as rendered on a page with css/inline style vs. that same element rendered in the same DOM structure without external CSS and with inline styles stripped; maybe inside a hidden iframe etc. Does that make sense?
Depending on your comfort level, you could have some luck looking into Firebug Lite sources.