Contents | Start | End | Previous: KB0433: Why does text overflow when previewing fixed layout books? | Next: KB0435: How can I remove line breaks at the end of paragraphs?


KB0434: Can I vertically align an image or text on a page?

Vertical alignment is hard to do in ebooks because HTML has traditionally been poor at this, and more recent HTML and CSS that might support it (such as the flexbox) isn't implemented widely in ebooks.

Ebook readers don't tend to honour 100% box and table height - if they did, then you could vertically align the contents of a box or table, and it would be vertically aligned within the page.

There is a workaround that might or might not work depending on the content. If you have a single image on a page, you could set its height to 50%. Then in front of the image in its own paragraph, paste or insert a small white image, e.g. 1px x 1px, and give it a height of 25%. If you use paragraph styles without space before/after, and the images don't have margins, then the result should approximate to a centred image.

However, if you have more content on the page than a single image, you can't predict what size the element will be and it won't work. Also, fixing the height might cause width overflow depending on the aspect ratio of the image and the display, although this risk is lessened for a portrait image.


Contents | Start | End | Previous: KB0433: Why does text overflow when previewing fixed layout books? | Next: KB0435: How can I remove line breaks at the end of paragraphs?