Skip to content

CssText doesn't include text-shadow's color if it's black #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mganss opened this issue Jan 3, 2022 · 3 comments
Closed

CssText doesn't include text-shadow's color if it's black #97

mganss opened this issue Jan 3, 2022 · 3 comments
Labels

Comments

@mganss
Copy link
Contributor

mganss commented Jan 3, 2022

var html = @"<div style=""text-shadow: 2px 2px 2px #000"">test</div>";
var parser = new HtmlParser(new HtmlParserOptions(), BrowsingContext.New(Configuration.Default.WithCss(new CssParserOptions())));
var dom = parser.ParseDocument(html);
var div = dom.QuerySelector("div");
var style = div.GetStyle();
var css = style.CssText;
// -> "text-shadow: 2px 2px 2px"

Also, if you set the blur radius to 0px it will be omitted from CssText as well.

@FlorianRappl
Copy link
Contributor

Well, these are the default values, which are optional.

So if you run:

<body style="text-shadow: 2px 2px 2px">
The content of the body element is displayed in your browser.
</body>

it looks the same as

<body style="text-shadow: 2px 2px 2px black">
The content of the body element is displayed in your browser.
</body>

The default ones are omitted when serializing - they don't add any value.

@mganss
Copy link
Contributor Author

mganss commented Jan 5, 2022

FWIW, browsers seem to behave differently:

var e = document.createElement("div");
e.innerHTML = '<span style="text-shadow: 2px 2px 0px black">test</span>';
e.firstElementChild.style.cssText
// -> "text-shadow: black 2px 2px 0px;"

It's exactly the same in both Chrome and Firefox. This is identical in both browsers as well:

e.innerHTML = '<span style="text-shadow: 2px 2px 0 #000">test</span>';
e.firstElementChild.style.cssText
// -> "text-shadow: rgb(0, 0, 0) 2px 2px 0px;"

@FlorianRappl
Copy link
Contributor

Yes, serialization is not part of the spec - but it does not matter much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants