2

This is the HTML code I use in my WinForms application:

<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>

When I save personally and used IE9 to display, it works fine, but when the WebBrowser uses it, the margin-top on #inf was not applied. Why? Isn't it the same IE I use? The same code display differently!

The proper render should have a gray box with margin around it and the white text should fix in the middle.

How to display properly using WebBrowser?

Eonasdan
  • 7,563
  • 8
  • 55
  • 82
Daniel Cheung
  • 4,779
  • 1
  • 30
  • 63

2 Answers2

6

Add the following to your HTML's header section:

<meta http-equiv="X-UA-Compatible" content="IE=9" >
Alex Filipovici
  • 31,789
  • 6
  • 54
  • 78
2

If the problem really is compatibility, see this question:

WebBrowser control will use whatever version of IE you have installed, but for compatibility reasons it will render pages in IE7 Standards mode by default.

If you want to take advantage of new IE9 features, you should add the meta tag <meta http-equiv="X-UA-Compatible" content="IE=9" /> inside the <head> tag of your HTML page.

Community
  • 1
  • 1
CodeCaster
  • 147,647
  • 23
  • 218
  • 272