A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/AngleSharp/AngleSharp.Css/issues/140 below:

External CSS not working from <link> · Issue #140 · AngleSharp/AngleSharp.Css · GitHub

Bug Report Prerequisites Description
    var config = Configuration.Default
      .WithRenderDevice(
        new DefaultRenderDevice {
          DeviceWidth = 1920,
          DeviceHeight = 1080
        })
      .WithDefaultLoader(
        new LoaderOptions() {
          IsNavigationDisabled = true,
          IsResourceLoadingEnabled = true
        })
      .WithCss();

    var context = BrowsingContext.New(config);
    var doc = await context.OpenAsync(req => req.Content(@"""
      <html>
        <head><link href=""https://some/tested/url.css"" rel=""stylesheet""></head>
        <body><label>HI</label></body>
      </html>
    """));

    /*var style = doc.CreateElement<IHtmlStyleElement>();
    style.TextContent = File.ReadAllText("some/actual/file.css");

    doc.Head?.AppendElement(style);*/

    var window = doc.DefaultView;
    var tree = window.Render();
    var label = tree.Find(doc.QuerySelector("label"));

    await label.DownloadResources();

    Console.WriteLine($"min-width: {window.GetComputedStyle(label.Ref as HtmlElement).GetMinWidth()}");

The css file has:

label, .test {
  min-width: 50px;
  border: 1px solid green;
}

If you uncomment the adding IHtmlStyleElement, it will work (injecting style directly), but when using the <link> it won't get processed.

Steps to Reproduce

Use code above.

Expected behavior: GetMinWidth() should return "50px" like it does when I add an IHtmlStyleElement directly.

Actual behavior: GetMinWidth() returns ""

Environment details: Windows 11, .NET 7


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4