The WebBrowser appears to be completely ignoring the CSS background-color property

To the best of my knowledge, the syntax and values seem correct. Please see the code snippet below.

* { 
  overflow: hidden; 
  background-color: rgba(30, 30, 30, .9); 
  color: rgb(242, 238, 229); 
  font-size: 18px; 
  font-family: Segoe UI,...;
}

The only property that appears to be ignored is background-color. Using !important did not make a difference.

Here is the template HTML:

<!DOCTYPE html>
<html>
  <head>
    <link rel='stylesheet' type='text/css' href='data:text/css;charset=UTF-8,{0}'>
  </head>
    <body>
      {1}
    </body>
</html>

(The {0,1} placeholders are used for formatting in a C# WPF application and then passing the HTML code to an embedded WebBrowser)

The 0 corresponds to URI encoded CSS, which works as intended.

Below is the segment of code from my WPF application:

TextRange rng = new TextRange(
    TextEntry.Document.ContentStart,
    TextEntry.Document.ContentEnd);

string cssString = ":not(h1,h2,h3,h4,h5,h6) { font-size: 11px; } * { overflow: hidden; background-color: rgba(30, 30, 30, .9); color: rgb(242, 238, 229); font-family: Segoe UI...; }";

string htContent = string.Format("<!DOCTYPE html><html><head><link rel='stylesheet' type='text/css'" 
                   + "href='data:text/css;charset=UTF-8,{0}'></head><body>{1}</body></html>",
                   Uri.EscapeUriString(cssString),
                   Markdig.Markdown.ToHtml(rng.Text));

Unfortunately, no matter how specific I make the background-color property, it remains unresponsive.

For reference, here is the XAML code for the WebBrowser in my application:

<WebBrowser x:Name="Markdown" HorizontalAlignment="Left" Height="406" Margin="16,36,-9,0" VerticalAlignment="Top" Width="800" Grid.RowSpan="2"/>

All other similar issues I found were due to an element overriding the style, but since this HTML and CSS are fairly standard, I couldn't pinpoint any such conflicts.

Answer №1

You should consider using the recent browser control option, which is WebView2. It could potentially solve your issue.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for positioning a div relative to another div while controlling its z-index

Hey there, take a look at the image below https://i.sstatic.net/zYiaY.png The issue I'm facing is quite common - I have div 1 and div 2 visible in a loop, but divs 3 are hidden. When div 2 is clicked on, everything is great so far. However, what I wa ...

Learn the technique for submitting a checkbox value regardless of its disabled status

I'm currently working on a web page that displays order invoices with pricing. Users can select items by checking the checkboxes and clicking submit. I want to restrict users from unchecking the items once they are selected, and the form should only w ...

Limit the text input area in HTML to a fixed size, preventing any text from exceeding the specified boundary

Is there a way to create a fixed line text area that limits the user from typing beyond a certain number of lines and maximum width? My current CSS styling for this is as follows: .area-style { resize: none; width: 324px; height: 200px; m ...

Navigational inconsistency with SVG icons integrated into Bootstrap Navbar

Bootstrap offers icons in embedded SVG format. These SVG tags can be directly added to HTML code. However, when I included the SVG tag in my navbar, the icon did not appear centered even after using the vertical-align: middle CSS property. The icon did not ...

Encountering a configuration file issue when attempting to consume a WCF service using an Ajax

Currently, I am encountering an issue when trying to consume a WCF service using jQuery. The error message I received is "Configuration binding extension 'system.serviceModel/bindings/webHttpbinding' could not be found. Verify that this binding e ...

Radio buttons in 'Block Style' functioning perfectly on all devices except for iPad

I am facing an issue with a group of radio buttons that I have styled to display as block elements, making them look like buttons while hiding the actual radio button itself. This setup works perfectly on Chrome and Firefox on desktops and Android tablets, ...

A server error has resulted in an application malfunction

Attempting to access an aspx page from an IIS server, where a registration form is located. While the browser successfully opens the page, encountering an error when trying to input values into the fields and save them: Description: A server application ...

Is it possible to alter the cursor according to the position of the mouse?

Is it possible to change the cursor from default to pointer when the mouse enters the specific rectangle area (50, 50, 100, 100) of the body? The dimensions are in pixels. Instead of defining a separate div and setting the cursor style on it, I'm loo ...

Instructions on placing the bottom of an inline-block element flush with the bottom of a block element

In the scenario where I have the following HTML and CSS code: .something{ width: 200px; } .display-block { display: block; } .req-field{ float: right; font-size: 5px; } <div class="something"> <span class="display-block">First name ...

The functionality of the add button suddenly ceased to work once multiple rows were added to the data table

I have encountered an issue while storing a data table in a gridview without using a database. Initially, everything was working fine, but after adding the 20th row, the ADD button stopped functioning properly. I am unable to identify the root cause of thi ...

The alignment of my Navbar Brand is off in my Navigation Bar and won't align to

<body> <nav class="navbar navbar-expand-lg navbar-dark bg-dark"> <div class="container-fluid"> <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs ...

Tips for resolving Layout Shift issues in responsive images utilizing the picture & source HTML tags

One issue I encountered with the <source> element is that even when specifying the width and height attributes for both the <source> and image fallback, there is still significant layout shift. This could be due to using images with varying dim ...

Updating existing text to create personalized HTML dropdown menus

I have designed a unique set of dropdowns by using divs and checkboxes instead of the traditional elements My goal is to dynamically change the 'select-wrapper--title' text (e.g. the first option) based on the selected option in the dropdown I ...

creating URLs using javascript

I am seeking guidance on how to dynamically generate URLs for different languages using JavaScript. When the server sends JSON data to the frontend, I have a header file and a helper function that helps in creating URLs in JavaScript. I am trying to figu ...

An error of type 'System.Web.HttpException' occurred during the file upload process to the server

Recently, I have started learning about asp.net, ajax, and c#. I am attempting to save an image on the server using the example below: <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> ...

Set boundaries for the width and height of an image in the input field

Looking to restrict the size of an image in an input field using HTML, CSS, and JavaScript/jQuery. Goal is to maintain a perfect square aspect ratio for profile photo uploads (for example, 200x200 or 300x300). ...

parsing the data from an HTML document containing embedded variables

Is there a more efficient way to use file_get_contents() on an html file containing 3 variables and have those variables populated with data from $_POST? For example: -html file- <html> . . <table> <tr> <td> ...

In the world of Angular, whitespace is simply treated as non-existent when it comes

Within the controller, I have an array structured as follows: 'Pipe': '|', 'Comma': ',', 'Tab': '\t' }; When configuring ng-options in my code, it is implemented in this manne ...

Activate the CSS on a click event using the onClick method

I am trying to implement a transition that triggers when clicking on a specific div element. Currently, the transition only occurs with the active css class. How can I achieve this effect by simply clicking on the div itself? I am using reactjs and believe ...

Jquery Droppable issue arising with dynamically added DIVs

I am facing a similar issue as described in this question and this one I am trying to implement drag-and-drop and resize functionality. It is working fine for static elements, but I encounter issues when adding dynamic divs. The resize property works prop ...