I'm trying to style a volume of poetry in the EPUB format. The poems need to appear horizontally centred despite the width of the page and width of the poem being unknown.
I've managed to do this in two different ways by following a couple of the answers to this question: Centering div with unknown width.
Both methods work in Sigil and in my browser but fail differently in some major e-book reading environments.
I tried thirtydot's method:
HTML:
<div id="container">
i'm as wide as my content
</div>
CSS:
body {
text-align: center;
}
#container {
text-align: left;
border: 1px solid red;
display: inline-block;
/* for ie6/7: */
*display: inline;
zoom: 1;
}
Unfortunately, this seems to be problematic in Callibre, Adobe Digital Editions and the many e-reading software programs that use its engine, as the use of display: inline-block
causes poems or verses using the style to flow over the edge of the viewport and the missing content is skipped over when moving on to the next page.
The method described by Nate B is also problematic in Adobe Digital Editions (as well as in Callibre, I believe):
#wrapper {
position: relative;
left: 50%;
float: left;
}
#page {
position: relative;
left: -50%;
float: left;
}
Adobe Digital Editions' implementation of margin:auto
is apparently (see http://www.mobileread.com/forums/archive/index.php/t-161097.html) not compatible with its use to center align elements. Using the above method seems to place the poems off screen.
Is there any way of centering a div with an unknown width without using margin:auto
, display:inline-block
or javascript (which is not usually supported by many e-reading programs)?
display: inline-block;
causes poems or verses using the style to flow over the edge of the viewport and the missing content is skipped over when moving on to the next page." – PrettyHands Jan 19 '16 at 22:27