widthproperty to images properly. Despite the fact that the spec says that
widthapplies to all elements except non-replaced inline elements, and that images are replaced inline elements, up til now, iBooks wouldn't apply
img. There is a workaround: applying the
widthto the image's parent, and setting the
widthof the image itself to 100%, as I describe in that article.
What's more frustrating is that since InDesign follows the rules, dutifully applying the pixel or percentage dimensions in the CSS directly to the image—which again, should work but doesn't in iBooks—those images are not displayed properly in iBooks.
So here's a document in InDesign: (I'm showing you the example in InDesign, but I would have the same issue if I created the code myself from scratch.)
Here's the code that InDesign generates when I choose "Preserve appearance" and "Relative to page"
And here's how iBooks displays that page:
I wrote Douglas Waterfall, Engineering Architect on InDesign, about the problem and he pointed me to the solution, right there in the iBooks Asset Guide (which you can download if you have an iBookstore account).
The solution consists of creating a super-charged or magic CSS class that you can then use to properly apply the
imgelements in iBooks. And it won't confuse ereaders that already do.
First, in the content.opf file, you have to make sure you have declared the iBooks namespace in the package element. You need this namespace if you use iBooks versioning as well. And it's completely harmless for non iBooks ereaders. (Note that I'm doing this in EPUB 3. I don't know and haven't tested it in EPUB 2.)
prefix="ibooks: http://vocabulary.itunes.apple.com/rdf/ibooks/vocabulary-extensions-1.0/" version="3.0" unique-identifier="bookid">
Next, in the
metasection of the content.opf file, define which class should be able to apply the
I called my class respect, but you can call it whatever you like.
Next, in the HTML, apply the respect class to your images.
<p class="Basic-Paragraph"><span><img class="respect" src="image/imagefolder-2_fmt.png" alt="imagefolder-2.jpg" /></span></p>
You can actually create multiple classes, as long as they are equal to, or prefaced with the name you declared in the meta element. So I could use respect, respect-wide, respect-small, or whatever.
Finally, create a rule in your CSS that references the respect class and applies the
(Of course, if you're using InDesign, you can simply create a style called respect and let InDesign create your HTML and CSS.)
And then, miracle of miracles, iBooks applies the
widthproperty, just as it should.
Seems crazy that we have to help iBooks follow the spec properly, but at least we can.
If you like this post, please consider subscribing!