【问题标题】:get html element font-size获取html元素字体大小
【发布时间】:2013-10-28 19:01:04
【问题描述】:

我想获取网页中 html 元素的字体大小,例如 <p> 标记。 即使对于没有 styleclass 属性的元素,这也应该是有效的,因此它必须知道动态继承的 css 属性。

我尝试过使用 html agilitypack,一个非常好的库,但它当然不考虑 css 渲染。也尝试使用 WPF webbrowser,但它似乎无法获取每个元素的字体大小,并且对于其中许多元素,它返回一个百分比。

Javascript getComputedStyle() 不适合,因为它们都应该运行在服务器端。

有什么想法吗?

【问题讨论】:

  • 你试过currentStyle属性吗? stackoverflow.com/questions/1905766/…
  • 为什么需要这个?你想要这个的背景很重要吗?
  • 上下文是从网页中提取文本文章,因此了解被解析文本的大小很重要。

标签: c# html dom


【解决方案1】:

试试这个:

Element.prototype.getStyle = function (prop) {
    if (document.defaultView) 
        return document.defaultView.getComputedStyle(this, null)[prop];
    else 
        return this.currentStyle[prop];
}

呼叫:

document.getElementById("div1").getStyle("font-size");

【讨论】:

  • 谢谢,但它必须是服务器端进程,我需要 C# 来了解网页中的文本大小...
  • 如果我理解你的话,你不能只用C#来做......为什么你不使用ajax?
猜你喜欢
  • 2017-01-14
  • 2010-12-29
  • 2015-05-24
  • 2013-02-18
  • 1970-01-01
  • 2010-11-21
  • 1970-01-01
  • 1970-01-01
  • 2017-09-19
相关资源
最近更新 更多