![]() |
#16 |
Enthusiast
![]() Posts: 28
Karma: 10
Join Date: May 2010
Location: Stockholm
Device: iPhone, iPad, Nook, Bookeen, Sony Reader
|
These are pretty sweet solutions, I'm trying to make so that a bunch of text, say 10 rows, would be centered in the middle both horizontal and vertical. Now only the top of the piece of text gets centered.
![]() |
![]() |
![]() |
![]() |
#17 |
frumious Bandersnatch
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 7,531
Karma: 19000001
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
|
There is no reliable way to do it.
|
![]() |
![]() |
Advert | |
|
![]() |
#18 |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 714
Karma: 2003751
Join Date: Oct 2008
Location: Ottawa, ON
Device: Kobo Glo HD
|
|
![]() |
![]() |
![]() |
#19 |
frumious Bandersnatch
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 7,531
Karma: 19000001
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
|
In my experience, because the screen height is not always accessible. You set the "wedge" height to 50%, expecting it to be 50% of the screen height (because you set the body's height to 100%, expecting it to be 100% of the screen/page height). From what I understand of the CSS specs and my (not exhaustive) tests, this is not guaranteed to work, and indeed it often does not, different renderers make different assumptions about what this "100%" refers to: some interpret is as "100% of the width", some simply ignore it, and so the "50%" also has different results.
|
![]() |
![]() |
![]() |
#20 | |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 714
Karma: 2003751
Join Date: Oct 2008
Location: Ottawa, ON
Device: Kobo Glo HD
|
Quote:
Sounds well defined, and looks like non-standard behaviour, for renderers where initial screen height is unknown/undefined. I would be grateful if you can name those renderers where a xhtml code segment would fail to produce the desired effect. |
|
![]() |
![]() |
Advert | |
|
![]() |
#21 |
frumious Bandersnatch
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 7,531
Karma: 19000001
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
|
I confess I have not tried your exact piece of code, but some time ago I tested similar codes including relative heights. I seem to recall it didn't work in Prince (XHTML to PDF renderer), and it often had problems in Opera and ADE.
You are probably right in that according to the CSS spec, but I'm afraid renderers seem to consider themselves as "continuous" rather than "paged". Of course, I could be wrong, I may remember incorrectly or have made mistakes in my tests, but my conclusion was that I could not get it to work as expected. |
![]() |
![]() |
![]() |
#22 | |
Enthusiast
![]() Posts: 28
Karma: 10
Join Date: May 2010
Location: Stockholm
Device: iPhone, iPad, Nook, Bookeen, Sony Reader
|
Quote:
I also tried it on the Bookeen and got the same result as on the iPad. iPad ![]() Stanza (iPhone) ![]() ADE ![]() |
|
![]() |
![]() |
![]() |
#23 |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 340
Karma: 43106
Join Date: Apr 2009
Location: Germany
Device: BeBook One, Pocketbook Touch, Pocketbook Touch HD
|
I tried it with Ankhs code, on one line and it works great with calibre. Thanks
This should be made sticky on the top of the forum. Or it should be included in the epub code snippets thread. Now, what I haven't tried so far (but will soon do) is: what is, when the line is longer then the screen? |
![]() |
![]() |
![]() |
#24 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 44,295
Karma: 23661992
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
@Nascaraddicted: This and several other advanced techniques are demonstrated in the calibre epub demo (linked to in the epub section of the conversion section of the calibre user manual)
|
![]() |
![]() |
![]() |
#25 |
Enthusiast
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 43
Karma: 100000
Join Date: Jun 2018
Device: none
|
I'll try Ankhs' code,* but also, I found a nice simple way to center vertically and horizontally without SVG:
Essentially I create a div of the same size as the viewport (might need to reduce it to 95vh to avoid displacement caused by renderer's compulsory margins). As of 2018, ADE still doesn't support vertical-align:middle. Code:
<!DOCTYPE html> <html> <head> <style> img { display: inline-block; vertical-align: middle; max-width: 100%; max-height: 100vh; } p.Vertical { text-align: center; line-height: 100vh; } div.Vertical { height:100vh; width:100vw; } body {margin: 0} </style> </head> <body> <div> <p class="ex"> <img src="paris.jpg" alt="Paris"> </p> </div> </body> </html> Last edited by Land_Outcast; 07-27-2018 at 02:48 PM. |
![]() |
![]() |
![]() |
#26 |
A Hairy Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,162
Karma: 18843349
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 15/11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
|
This has worked for me for several years. I wish I could remember who I got it from on the internetz...
I think it was Hitch that mentioned Kindle/Amazon doesn't like Tables, but I'm not sure if "doesn't like" equates to "doesn't work". ![]() edit: The technique doesn't actually use "tables" it simply uses the properties of tables in the CSS for "display:table-cell". You can have any number of items within the inner div and it'll vertically center on the page. Works great for title pages, dedications, Book/Part headings, etc. Cheers, Code:
<head> <title>Vertical Center</title> <style> /* Vertically centered on page */ div.v-ctr {height:100%; width:100%; display:table; position:fixed; padding:0; margin:0; text-indent:0} div.v-ctr div {display:table-cell; vertical-align:middle; padding:0; margin:0} </style> </head> <body> <div class="v-ctr"> <div> <p>Centered</p> </div> </div> </body> </html> Last edited by Turtle91; 07-27-2018 at 04:28 PM. |
![]() |
![]() |
![]() |
#27 | ||
Bookmaker & Cat Slave
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,473
Karma: 158448243
Join Date: Apr 2010
Location: Phoenix, AZ
Device: K2, iPad, KFire, PPW, Voyage, NookColor. 2 Droid, Oasis, Boox Note2
|
Quote:
Quote:
Hitch |
||
![]() |
![]() |
![]() |
#28 |
A Hairy Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,162
Karma: 18843349
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 15/11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
|
Thanks Hitch - I'm starting to remember some of the things I think I forgot, maybe, I'm not sure...
![]() |
![]() |
![]() |
![]() |
#29 |
Enthusiast
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 43
Karma: 100000
Join Date: Jun 2018
Device: none
|
And how would we center paragraph for reflowable ebook in ADE?
(Meaning we don't know its final height, and we can't use vertical-align.) (And, remember, idpf won't allow for absolute positioning.) Last edited by Land_Outcast; 07-31-2018 at 09:34 PM. |
![]() |
![]() |
![]() |
#30 |
A Hairy Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,162
Karma: 18843349
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 15/11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
|
The code I mentioned above works for me. However you need to use it properly....short paragraphs...typically only a line or two that you could actually discern as being v-centered - especially on a small screen. There is a difference between position:absolute and position:fixed.
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Center a cover image | Crusader | Sigil | 2 | 10-18-2009 08:51 AM |
Using Bookdesigner...Center title up and down | davers | LRF | 5 | 04-24-2009 09:53 AM |
How to center 10% hr on ADE/PRS505 | Ankh | ePub | 5 | 04-16-2009 10:05 PM |
Support center iRex | ce3po | iRex | 3 | 12-21-2007 07:52 AM |
Mobipockets v6.1 is up in the beta center | penty | Bookeen | 4 | 11-06-2007 06:31 PM |