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
HTML5.css, the CSS cascade, and other stylesheet questions #551
Comments
This seems to be correct, somewhat to my surprise because not doing this is something I've traditionally been a bit unhappy about in how browsers (and iirc CSS 2.1) implemented user stylesheets, always requiring the use of !important to override things with all of the unintended consequences that entails.
This intuitively makes sense to me, unless you think it's too simple. :-) |
No real question, just writing my thoughts, so someone can stop me if I don't think right. So, there are "presentational hints", some that can be expressed in our user-agent stylesheet, ie. in html5.css: ol[type=a s], li[type=a s] { list-style-type: lower-alpha; }
table[align=left i] { float: left; } and others that can't, and are formulated as text, ie.:
We don't support any of these complex/wordly rules with EPUBs (but there is code for standalone HTML that do translate The thing is we have been mostly fine without support for them for years, so I'm afraid this could sometimes give additional formatting we don't want, ie. when saving HTML pages from the web to HTML or EPUBs, we may get lots of So, initially, I thought it would be nice to tag such CSS with a cr-hint, ie: ol[type=a s], li[type=a s] {
-cr-hint: presentational;
list-style-type: lower-alpha;
}
table[align=left i] {
-cr-hint: presentational;
float: left;
} so we can have style tweaks to make these inneffective, ie. Does this feel overkill? Anyway, having read the specs I mentionned in the first post, I think we still need these For the complex/wordly presentational hints, if I want to have the same CSS cascade rules applied, I think I need to have them expressed in the same useragent stylesheet. font[color] {
-cr-hint: presentational;
-cr-apply-func: htmlcolor2csscolor;
}
font[size] {
-cr-hint: presentational;
-cr-apply-func: htmlsize2cssfontsize;
} and have some generic C code to handle these named "apply functions" to parse the attribute value and apply it to the CSS property for a matching node (instead of having all that hardcoded in the C code). Thoughts? |
So it's supposed to go
I'm not sure if that sounds much easier, but if the apply functions can be done in Lua it could potentially open up some interesting scripting possibilities in any case. |
Yes, I think so.
No, that would make the ordering different and not right: regular CSS,
Oh, no, out of scope and would probably be too slow with the round trips between Lua and C :) |
It doesn't sound intuitive to me that some regular CSS would have higher priority without !important, but oh well.
Well, whatever you think is best. :-) |
I'd like to update our html5.css to conform to the current HTML specs:
https://html.spec.whatwg.org/multipage/rendering.html
(I initially based it on this very old https://github.com/FriendsOfEpub/WillThatBeOverriden/blob/master/ReadingSystems/html5/html5.css , which has a lots of old rare stuff now removed)
I also would like to find a solution to properly and consistently handle HTML attributes - cf buggins/coolreader#214 (comment).
So, writing all the following to get confirmation that:
So, the HTML specs do not give a full user agent stylesheet, but there are snippets in the "rendering.html" page that I could just copy and concatenate. (There are also writings, for things that can't translate easily to CSS, about how stuff should work, more on that later...)
In their writing, they speak about presentational hints.
I've always read "presentational" somehow as "optional" :) and was fine not having them or having only parts of them... But no, it means:
And https://www.w3.org/TR/css-cascade-3/#preshint (striking out the alternative that is not the one decided by HTML):
I initially thought I could just get away with them by using
table[align=left i] { --cr-hint: zero-specificity; float: left; }
and have crengine put them at the start of the selector chain, but it looks like it's not the way this should work :)I guess they should just be after all the user-agent & user selectors - so before the authors/publisher stylesheet ones.
And they may usually be just there, as they often/always use attribute selectors [ie.
table[align]
), so get a higher specificity than the normal user agent selectors (usually justtable {}
), so they end up after them.But re-reading about the CSS cascade: https://www.w3.org/TR/css-cascade-3/#cascading, I see we have other problems :/
Can you confirm that I read that right: each of these 8 "stylesheets" should all be applied independently, and that a lower-specificity in the author stylesheet should be applied AFTER a higher specificity in the user-agent stylesheet - that is, the ordering of specificity is done independantly in each of these 8 stylesheets/origins. (Also see below, my point about selector and declarations and
!important
...)I can confirm that with Firefox
It has in its UA stylesheet:
table[align="right"] { float: right; }
and if I put a lower specificity in my HTML
<style>
:table { float: none; }
or even lower:* { float: none; }
my
<table align="right" ...>
does not float any longer.This does not happen with KOReader/crengine.
So, the problem we have is that we have only one selectors chain, and when parsing authors (publishers) stylesheets, we insert these new selectors into the main (user-agent+user tweaks) stylesheet, and we insert them by ensuring specificity ordering as if it was all a single origin.
So, we end up placing
* { float: none; }
(so it is applied first) beforetable[align="right"] { float: right; }
(so it ends up being applied, while it shouldn't).In crengine, there is some gymnastic when we process authors stylesheets:
Possible solutions:
Do each sound like it would work and be enough?
About the whole cascade origin stuff, for us it could be simplified:
1 Transition declarations [css-transitions-1]Not applicable for us2 Important user agent declarationsThere isn't any in the specs, and we shouldn't need any (or if any need of that kind, it's usually hardcoded and enforced in the code).3 Important user declarations
4 Important author declarations
5 Animation declarations [css-animations-1]Not applicable for us6 Normal author declarations
7 Normal user declarations
8 Normal user agent declarations
It's a bit confusing, as this talks about declarations, and not selectors. And selectors may have declarations with both normal properties and
!important
properties....So, I'm not really sure it says what I thought about selectors chains above :/
Anyway, assuming I'm somehow not too in space, and selectors can still be ordered as I wrote above:
We actually do ensure (3) not overridden by (4) with our !important and higher_importance bits that we associate to each property on each style.
The (6) not overridden by (7+8) would be ensure by the solutions outlined above.
There is still (7) vs (8) that we may not ensure, because they both end up in the useragent stylesheet, but I guess that can be ok. The epub.css and html5.css are quite generic/low-specificity, and a user tweaking style tweaks can always help himself solving any issue.
The text was updated successfully, but these errors were encountered: