Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Formats > ePub

Notices

Reply
 
Thread Tools Search this Thread
Old 09-27-2024, 02:44 PM   #1
Fitz Frobozz
Enthusiast
Fitz Frobozz began at the beginning.
 
Fitz Frobozz's Avatar
 
Posts: 28
Karma: 10
Join Date: May 2024
Device: Kindle Scribe
Align text to top in columns

I'm struggling with CSS issue involving a parent div and a couple of child divs that I want aligned to the top. The document is ePub 3 and when done I intend to create an ePub 2 version for more device compatibility.

The CSS seems fine and both Caliber and Sigil render the content as expected (both container and children all align to top of page), but on my Kindle Scribe (and presumably on other Kindle readers) the second of the two child divs aligns to the bottom of the parent container instead.

Here's the CSS (the first applies to the parent container, the second to the child divs). Any suggestions?

Code:
.content-top {
  display: flex;
  grid-template-columns: 1fr 1fr;
  align-content: flex-start;
  vertical-align: top;
  font-size:.85em;
}
.float-container {
  align-content: flex-start;
  align-self:start;
  vertical-align: top;
}
Would prefer to stick with a solution like this one if possible, but I'm open to alternatives, especially if something suggested has wider reader support.

Edit: Just noticed that this relevant to this thread. Not seeing any clear solutions there, however.

Last edited by Fitz Frobozz; 09-27-2024 at 02:49 PM.
Fitz Frobozz is offline   Reply With Quote
Old 09-27-2024, 04:49 PM   #2
RbnJrg
Wizard
RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.
 
Posts: 1,606
Karma: 8291219
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
Kindle doesn't honor the property "display: flex", so you can't use it in a .KFX ebook. And this other property you are employing "grid-template-columns" is for "grid layouts"; you can't use it with "display: flex" but with "display: grid".

Regarding a solution for your issue (it seems that you are looking for something that also works on Kindle), can you post an image of the desired output? Post that and I will be able to help you more.
RbnJrg is offline   Reply With Quote
Advert
Old 09-27-2024, 07:26 PM   #3
Fitz Frobozz
Enthusiast
Fitz Frobozz began at the beginning.
 
Fitz Frobozz's Avatar
 
Posts: 28
Karma: 10
Join Date: May 2024
Device: Kindle Scribe
That makes sense and I had a feeling that would be what's going on here. I'd planned on starting with what I'd do normally and then tweak/revamp as required, but then I realized that I'm not very clear on what is and isn't supported on various devices.

Anyway, here's an illustration of what I am looking for and what gets rendered on the Scribe:
Attached Thumbnails
Click image for larger version

Name:	column-text-rendering.png
Views:	44
Size:	15.0 KB
ID:	211059  
Fitz Frobozz is offline   Reply With Quote
Old 09-27-2024, 09:40 PM   #4
RbnJrg
Wizard
RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.
 
Posts: 1,606
Karma: 8291219
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
Quote:
Originally Posted by Fitz Frobozz View Post
That makes sense and I had a feeling that would be what's going on here. I'd planned on starting with what I'd do normally and then tweak/revamp as required, but then I realized that I'm not very clear on what is and isn't supported on various devices.

Anyway, here's an illustration of what I am looking for and what gets rendered on the Scribe:
Ok, that is easy and you don't need to employ a flex-box. Here you have an aproximation that works on both, epub and KFX:

1. In your .xhtml file:

Code:
  <div class="left">
    <p>Lorem Ipsum</p>

    <p>Lorem Ipsum</p>
  </div>

  <div class="right">
    <p>Lorem Ipsum</p>
  </div>
2. In your .css file:

Code:
p {
  margin: 0; /* or whatever you want */
  line-height: 1.2em; /* or whatever you want */
  text-align: left; /* or whatever you want */
}

.left {
  float: left;
  width: 49.75%;
}

.right {
  float: right;
  width: 49.75%;
}
Use the above code and your epub will be compatible with epub2/3 ereaders and also with Kindle. An alternative could be to employ two divs with the property "display: inline-block"; something like the following:

1. The same for .xhtml file
2. In you .css file:

Code:
p {
  margin: 0;
  line-height: 1.2em;
  text-align: left;
}

.left {
  display: inline-block;
  width: 49%; /* Here you have to employ a smaller width; before you had 49.75% */
  vertical-align: top;
}

.right {
  display: inline-block; 
  width: 49%; /* Here you have to employ a smaller width */
  vertical-align: top;
}
But for this case, I prefer to employ the solution based on the property "float".

Last edited by RbnJrg; 09-27-2024 at 09:53 PM.
RbnJrg is offline   Reply With Quote
Old 09-28-2024, 01:45 AM   #5
Fitz Frobozz
Enthusiast
Fitz Frobozz began at the beginning.
 
Fitz Frobozz's Avatar
 
Posts: 28
Karma: 10
Join Date: May 2024
Device: Kindle Scribe
That's helpful, thanks a bunch. Dunno why the float property was giving me trouble when I was trying to use it for this (just before deciding to experiment with grid and flex), but it sounds like it should have been fine. I'll give it another go and report back.
Fitz Frobozz is offline   Reply With Quote
Advert
Old 09-29-2024, 01:57 AM   #6
Fitz Frobozz
Enthusiast
Fitz Frobozz began at the beginning.
 
Fitz Frobozz's Avatar
 
Posts: 28
Karma: 10
Join Date: May 2024
Device: Kindle Scribe
Option #3 did the trick. Seems there may be quirks/issues that disrupt vertical alignment for elements that are inside floated elements (or are floated themselves, as I was seeing the other day). In any case, thanks for taking the time and being so helpful!

This is what I ended up with, which aligns left- and right-hand columns to the left and to the right, and both columns to the top:

Code:
  <div class="top-outer-left">
    <div class="top-inner-left">
      Lorem ipsum: <em>dolor sit amet</em><br/>

      Ut enim ad minim veniam: 1234
    </div>
  </div>

  <div class="top-outer-right">
    <div class="top-inner-right">
      Duis aute irure dolor: 5678 (Excepteur sint occaecat)
    </div>
  </div>

.top-outer-left, .top-outer-right {
  width: 49%;
  display: inline-block;
  vertical-align: top;
  font-size:.85em;
}

.top-outer-left {
  text-align:left;
}

.top-outer-right { 
  text-align:right;
}

.top-inner-left, .top-inner-right {
  margin: 0;
}

Last edited by Fitz Frobozz; 09-29-2024 at 02:16 AM.
Fitz Frobozz is offline   Reply With Quote
Old 09-29-2024, 11:04 AM   #7
RbnJrg
Wizard
RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.
 
Posts: 1,606
Karma: 8291219
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
Quote:
Thanks for taking the time and being so helpful!
No problem and glad that you were able to fix your issue by mean of the inlined blocks method.

And may be the solution based on floating blocks didn't work because of the witdh of the divs. I think that with a width of 49% instead of 49.75% could work (maybe you are using some margins that make a width of 49.75% too large).
RbnJrg is offline   Reply With Quote
Old 09-30-2024, 06:08 AM   #8
rjwse@aol.com
Addict
rjwse@aol.com ought to be getting tired of karma fortunes by now.rjwse@aol.com ought to be getting tired of karma fortunes by now.rjwse@aol.com ought to be getting tired of karma fortunes by now.rjwse@aol.com ought to be getting tired of karma fortunes by now.rjwse@aol.com ought to be getting tired of karma fortunes by now.rjwse@aol.com ought to be getting tired of karma fortunes by now.rjwse@aol.com ought to be getting tired of karma fortunes by now.rjwse@aol.com ought to be getting tired of karma fortunes by now.rjwse@aol.com ought to be getting tired of karma fortunes by now.rjwse@aol.com ought to be getting tired of karma fortunes by now.rjwse@aol.com ought to be getting tired of karma fortunes by now.
 
rjwse@aol.com's Avatar
 
Posts: 303
Karma: 2228060
Join Date: Dec 2013
Location: LaVernia, Texas
Device: kindle epub readers on android
Great explanation! I have been long wondering why dedicated ebook readers have been slow to incorporate flex and grid. Is it a low-power hardware issue? Even smart phones on android can with good ebook reader apps can do more than kindle or nook.
rjwse@aol.com is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
text-align-last degn Recipes 1 03-01-2019 04:14 PM
Kobo Touch Extended: vertical-align:top Francois_C Plugins 5 09-04-2015 12:57 PM
text-align:lol; odedta ePub 6 06-16-2014 09:40 AM
Cover Align Top esoteric Conversion 0 02-20-2013 12:19 PM
I can not align the text...help please! XD derfel_spain ePub 17 12-18-2010 09:45 AM


All times are GMT -4. The time now is 07:14 PM.


MobileRead.com is a privately owned, operated and funded community.