An issue has been brought up on Github: If an ebook has images that are
sized with a broadly-specific selector, then in the single-page web view
that broad selector will also select the titlepage image, incorrectly
sizing it. See for example
https://standardebooks.org/ebooks/william-faulkner/the-sound-and-the-fury/text/single-page
This shouldn't be solved by editing the ebook to make the selector more
specific, because the epub shouldn't care how the single-page view is
compiled.
Rather, we should think of a general purpose solution to isolate CSS in
the single-page view, in case the stylesheets or structuring change in
the future.
I think one solution would be to do the following when compiling the
single-page view:
- Walk each XHTML file
- Walk each included CSS file in the XHML file
- Walk each selector in the CSS file and add a class to any `body >
section, body > article` elements that is named after the file, like
`local-css`, and update the selector to prefix it with that class, like
`.local-css`
- Then, continue compiling the single-page view as usual.
For example, this input:
local.css:
img{
width: 10px;
}
chapter-1.xhtml:
<head>
<link href="local.css">
<link href="se.css">
<body>
<section>
<img>
would become:
local.css:
.local-css img{
width: 10px;
}
chapter-1.xhtml:
<head>
<link href="local.css">
<link href="se.css">
<body>
<section class="local-css se-css">
<img>
I *think* this should solve the issue. Does anyone see any problems or
does anyone have any thoughts on different approaches?
Also, would anyone be interested in working to implement this?