简体   繁体   中英

Get current style using MSHTML in C#

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM