![]() |
#1 |
Member
![]() Posts: 14
Karma: 10
Join Date: Sep 2013
Device: asus tf300
|
centering content
Hello,
I am creating some ebooks using html and calibre. I would like to emulate publisher pages in paper books, where the information is centered on the page. I have created a DIV with the content and centered it horizontally in the page. In calibre I set up <div> as a breaking page so it will stand alone. Because of the text re-flowing characteristics of epubs, I would like to know if there is a way to get around this property and center the content vertically and horizontally. Last edited by p_nut33; 07-18-2014 at 06:17 PM. |
![]() |
![]() |
![]() |
#2 |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
You could simply add a margin on top to push it downward. To my knowledge, there is no way to specify vertical centering in ebooks. But I could be wrong, and there are much more knowledgeable people here who will gladly pitch in.
![]() |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,337
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
I doubt there's any method that will work for all readers/devices. But the best technique I know of is to make an absolutely positioned div of fixed height and set its margins to auto.
This will of course only work if your vertically centered content is the only content in a single html file. A more complex, but similar in spirit technique is to use SVG. IIRC there is a demo of this in the calibre epub advanced formatting demo. |
![]() |
![]() |
![]() |
#4 |
eBook Enthusiast
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 85,544
Karma: 93383099
Join Date: Nov 2006
Location: UK
Device: Kindle Oasis 2, iPad Pro 10.5", iPhone 6
|
This question has nothing to do with Calibre. Moved to the ePub forum.
|
![]() |
![]() |
![]() |
#5 |
frumious Bandersnatch
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 7,546
Karma: 19001583
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
|
There's no sure way to center stuff vertically. This is because there's no sure way (according to the specification) to get the screen height. There are some tricks around that apparently work in some or even most epub readers, but that's more by chance than by design. The best solution is simply add some top margin (and if you add it in %, note that it refers to a percentage of the width, not of the height).
|
![]() |
![]() |
Advert | |
|
![]() |
#6 | |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 79,714
Karma: 145864619
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Quote:
Code:
.half { margin-top: 48%; font-weight: bold; text-align: center; text-indent: 0 } |
|
![]() |
![]() |
![]() |
#7 |
eBook Enthusiast
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 85,544
Karma: 93383099
Join Date: Nov 2006
Location: UK
Device: Kindle Oasis 2, iPad Pro 10.5", iPhone 6
|
No. As has been said, a margin width expressed as a percentage is actually taking a percentage of the page width, not the page height.
|
![]() |
![]() |
![]() |
#8 |
frumious Bandersnatch
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 7,546
Karma: 19001583
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
|
...even if it's a top margin. At least according to the CSS specifications. If a renderer behaves otherwise, it's flawed, even if you (or I) would like it better.
|
![]() |
![]() |
![]() |
#9 |
Obsessively Dedicated...
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,221
Karma: 35037583
Join Date: May 2011
Location: PA {back in the usa!}
Device: Sony PRS-T2, ADE on PC
|
Yes, easily tested by display in a tall narrow window with ADE.
And margin:auto is often not honored -- some readers set auto-margins to ZERO. ![]() |
![]() |
![]() |
![]() |
#10 |
eBook Enthusiast
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 85,544
Karma: 93383099
Join Date: Nov 2006
Location: UK
Device: Kindle Oasis 2, iPad Pro 10.5", iPhone 6
|
It's easy to test: display the same ePub on a screen with a 4:3 aspect ratio (most eInk devices, or an iPad) and on a device with a 16:10 aspect ratio (almost all Android devices). If the top margin is a percentage of the page width, the margin should be relatively narrower on the 16:10 device than on the 4:3; if it's genuinely honouring page height, it will the same (percentage-wise) in both cases.
|
![]() |
![]() |
![]() |
#11 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,337
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Like I said, use either margin:auto with a fixed size div, or if your target reader does not support that, use SVG, as is shown in this demo file (see the full screen image page, which includes vertically centered text).
http://manual.calibre-ebook.com/conv...ormatting-demo |
![]() |
![]() |
![]() |
#12 |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 79,714
Karma: 145864619
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
The code I posted does work in ADE. So any renderer that code fails to work with is broken.
|
![]() |
![]() |
![]() |
#13 |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 79,714
Karma: 145864619
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
|
![]() |
![]() |
![]() |
#14 | |
frumious Bandersnatch
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 7,546
Karma: 19001583
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
|
Quote:
Besides, it "assumes" that the text's height is more or less 4% of the screen. Increase the font size considerably (or make the text several lines long) and it will not be centered (or ADE is even more broken). |
|
![]() |
![]() |
![]() |
#15 |
frumious Bandersnatch
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 7,546
Karma: 19001583
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
|
Unfortunately, there's no reliable and compliant way of setting the SVG to full screen height. "height:100%" may work in most real-world readers, but that's not guaranteed.
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Centering blockquotes | ghostyjack | ePub | 6 | 07-17-2014 06:07 AM |
centering text | andreadavison | Conversion | 1 | 12-29-2013 02:02 PM |
Nook not centering anything. why? | kateharp | ePub | 0 | 05-11-2011 10:53 PM |
Centering PDF | nguirado | Amazon Kindle | 5 | 10-04-2010 08:45 PM |
How to do centering | sjohnson717 | Calibre | 15 | 02-28-2010 09:20 AM |