【问题标题】:WebBrowser style not applying properly in WinFormsWebBrowser 样式未在 WinForms 中正确应用
【发布时间】:2013-01-22 13:08:33
【问题描述】:

这是我在 WinForms 应用程序中使用的 HTML 代码:

<html>
<head>
<style>
    #vif {
    margin:20px 5px 5px 5px;
    background-color:#888;
    }
    #inf li {
    margin-left:40px;
    color:#fff;
    }
    #inf {
    margin-top:15px;
    padding-bottom:15px;
    display:inline-block;
    }
</style>
</head>
<body>
<div id="vif">
    <div id="inf">
        <li>Hello!</li>
    </div>
</div>
</body>
</html>

当我个人保存并使用IE9显示时,它工作正常,但是当WebBrowser使用它时,#inf上的margin-top没有应用。为什么?我用的不是同一个IE吗?相同的代码显示不同!

正确的渲染应该有一个灰色框,周围有边距,白色文本应该固定在中间。

如何使用WebBrowser正确显示?

【问题讨论】:

  • 你有什么IE版本?
  • @AlexFilipovici IE10,但这也适用于 IE9,但他们不是说 WebBrowser 与您的 IE 相同吗?

标签: c# winforms browser


【解决方案1】:

将以下内容添加到 HTML 的标题部分:

<meta http-equiv="X-UA-Compatible" content="IE=9" >

【讨论】:

  • 再次感谢您的帮助!和 CodeCaster 的
【解决方案2】:

如果问题确实是兼容性问题,请参阅this question

WebBrowser 控件将使用您安装的任何版本的 IE,但出于兼容性原因,它将默认以 IE7 标准模式呈现页面。

如果您想利用新的 IE9 功能,您应该在 HTML 页面的 &lt;head&gt; 标记内添加元标记 &lt;meta http-equiv="X-UA-Compatible" content="IE=9" /&gt;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-26
    • 1970-01-01
    • 1970-01-01
    • 2015-06-30
    • 2019-04-23
    • 1970-01-01
    • 2021-03-27
    相关资源
    最近更新 更多