简体   繁体   中英

Link Stylesheet to local html page in c# wpf application

I have a WPF with a browser control that points to a local HTML file.

I have my .html and .css files in a folder labelled WebResources but it seems no matter how I link the stylesheet in the index.html file the styling doesn't show.

My Solutions Explorer

Solution MyProject
-- MyProject
---- Properties
---- References
---- WebResources
  ---- Index.html
  ---- Style.css

Index.html

<!DOCTYPE HTML>
<html>
<head>
    <title></title>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">

        <link rel="stylesheet" href="WebResources\Style.css" />
        <!-- Also Tried "<link rel="stylesheet" href="Full\Path\To\Style.css" /> -->
</head>
<body>
    <div class="container">
        <h1>This should be very big</h1>
    </div>
</body>
</html>

Style.css

h1 {
    font-size: 10em;
}

If index.html and Style.css are in the same folder you should use:

<link rel="stylesheet" href="Style.css" />

I just tried with a test app and it works well. Let me know.

Have you tried forward-slashes (/)? html pages usually reference other resources with these rather than Windows-style back-slashes

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