Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Formats > ePub

Notices

Reply
 
Thread Tools Search this Thread
Old 06-25-2025, 02:16 PM   #1
robertmchicago
Enthusiast
robertmchicago began at the beginning.
 
Posts: 30
Karma: 10
Join Date: Apr 2025
Device: none
Hiding Other Answers in epub2

I am making a reflowable EPUB 2 book using Sigil. The book also has about 400 questions and 400 answers, divided into two parts: one part for the questions, and one part for the answers.
Each question has a link that goes to its answer, and each answer has a link that goes back to its question.
I want to make sure that when a reader clicks on a link to an answer, they only see that one answer, not the other answers.
One simple way is to put each answer in a separate HTML file, but KDP does not allow more than 300 HTML files.
I also tried using page breaks, but they don’t work properly on all devices like Kobo.
I know I can't use JavaScript because most eBook platforms don’t support it.
So, I want to ask: Will this idea work?

After each answer, I add this line in HTML:
<p class="endline">===============</p>

And in CSS:
p.endline {
font-weight: bold;
text-align: center;
margin-bottom: 100vh;
}
This puts a long space after each answer to push the next answer far down, so only one answer is seen at a time.
What do you think? Will this be a good way to solve the problem?
robertmchicago is offline   Reply With Quote
Old 06-25-2025, 02:38 PM   #2
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 79,612
Karma: 145864263
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
Quote:
Originally Posted by robertmchicago View Post
I am making a reflowable EPUB 2 book using Sigil. The book also has about 400 questions and 400 answers, divided into two parts: one part for the questions, and one part for the answers.
Each question has a link that goes to its answer, and each answer has a link that goes back to its question.
I want to make sure that when a reader clicks on a link to an answer, they only see that one answer, not the other answers.
One simple way is to put each answer in a separate HTML file, but KDP does not allow more than 300 HTML files.
I also tried using page breaks, but they don’t work properly on all devices like Kobo.
I know I can't use JavaScript because most eBook platforms don’t support it.
So, I want to ask: Will this idea work?

After each answer, I add this line in HTML:
<p class="endline">===============</p>

And in CSS:
p.endline {
font-weight: bold;
text-align: center;
margin-bottom: 100vh;
}
This puts a long space after each answer to push the next answer far down, so only one answer is seen at a time.
What do you think? Will this be a good way to solve the problem?
You do not want vh as it doesn't work in ePub2.
JSWolf is offline   Reply With Quote
Old 06-26-2025, 12:11 AM   #3
robertmchicago
Enthusiast
robertmchicago began at the beginning.
 
Posts: 30
Karma: 10
Join Date: Apr 2025
Device: none
Quote:
Originally Posted by JSWolf View Post
You do not want vh as it doesn't work in ePub2.
Thanks a lot, any suggestion for my problem, PLEASE
robertmchicago is offline   Reply With Quote
Old 06-26-2025, 03:10 AM   #4
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 79,612
Karma: 145864263
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
Quote:
Originally Posted by robertmchicago View Post
Thanks a lot, any suggestion for my problem, PLEASE
If you are using margin-bottom: 100vh; to mean no bottom margin, just use margin-bottom: 0;
JSWolf is offline   Reply With Quote
Old 06-26-2025, 07:10 AM   #5
Turtle91
A Hairy Wizard
Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.
 
Turtle91's Avatar
 
Posts: 3,345
Karma: 20171571
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
Quote:
Originally Posted by robertmchicago View Post
Thanks a lot, any suggestion for my problem, PLEASE
Have you used {page-break-after: always}?? Or any of its alternative forms...

Code:
<p class="answer">Answer to question #x</p>

.answer {
  page-break-after: always;
  break-after: always;
  -moz-column-break-after: always;
  -webkit-column-break-after: always;
  *// whatever styling you want //*}
or if you have multiple paragraphs in your answer:

Code:
<div class="answer">
  <p>Answer to question #x</p>
  <p>more answer</p>
  <p>even more answer.</p>
</div>

.answer {
  page-break-after: always;
  break-after: always;
  -moz-column-break-after: always;
  -webkit-column-break-after: always;
}
.answer p {*// whatever styling you want //*}
I think I remember hearing something about some readers treating everything as a column (whether single or multiple) so column-break-after might work for those??

Last edited by Turtle91; 06-26-2025 at 07:18 AM.
Turtle91 is offline   Reply With Quote
Old 06-26-2025, 07:31 AM   #6
Turtle91
A Hairy Wizard
Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.
 
Turtle91's Avatar
 
Posts: 3,345
Karma: 20171571
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
Quote:
Originally Posted by JSWolf View Post
You do not want vh as it doesn't work in ePub2.
Using vh as a bottom margin won't hurt anything if it is not supported in compliant renderers...as you well know.


I know - Just use fall-back coding.
Turtle91 is offline   Reply With Quote
Old 06-26-2025, 10:22 AM   #7
Slevin#7
Enthusiast
Slevin#7 began at the beginning.
 
Posts: 38
Karma: 10
Join Date: May 2025
Device: iPad
I don't know whether this specific solution works with Kindle formats, so you would have to try.

This approach won't split the question-answer segment into two sections, but will show the answer directly under each question. It relies on a checkbox and its :checked pseudo selector to toggle the visibilty of the answer:

HTML
Code:
<div class="question">
  <p>Is the sky blue?</p>

  <label for="checkbox-answer_1" class="toggle-answer">
    Click here to show/hide the answer.   
  </label>

  <!-- We have to place the checkbox outside the label element
         since otherwise targeting .answer wouldn't be possible.
         This requires an id to link the label to the checkbox. -->

  <input type="checkbox" id="checkbox-answer_1" class="checkbox-answer"/>

  <div class="answer">
    <p>Yes, the sky is blue.</p>
  </div>
</div>
CSS
Code:
.question {
  padding: 0.1em 1em;
  background-color: #eee;
}

.answer {
  visibility: hidden;
  background-color: #ddd;
}

.toggle-answer {
  cursor: pointer;
  /* prevent accidentally selecting */
  -webkit-user-select: none;
     -moz-user-select: none;
      -ms-user-select: none;
          user-select: none;   
}

/* hide the checkbox, not a must for functionality */
.checkbox-answer {
  position: absolute;
  top: -1000px;
  left: -6000px;
  width: 0;
  height: 0;
  opacity: 0;
}

.checkbox-answer:checked ~ .answer {
  visibility: visible;
}
Slevin#7 is offline   Reply With Quote
Old 06-26-2025, 11:11 AM   #8
robertmchicago
Enthusiast
robertmchicago began at the beginning.
 
Posts: 30
Karma: 10
Join Date: Apr 2025
Device: none
Quote:
Originally Posted by Turtle91 View Post
Have you used {page-break-after: always}?? Or any of its alternative forms...

[CODE]
<p class="answer">Answer to question #x</p>

.answer {
Thanks a lot for the suggestion!
I already have tested these codes:
page-break-after: always;
break-after: always;
They work in Kindle Previewer and ADE 2.0, but not in Kobo Desktop.

Now I tried these:
page-break-after: always;
break-after: always;
-moz-column-break-after: always;
-webkit-column-break-after: always;
But it's the same—they work in Kindle Previewer and ADE 2.0, but still not in Kobo Desktop.
robertmchicago is offline   Reply With Quote
Old 06-26-2025, 11:19 AM   #9
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 79,612
Karma: 145864263
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
Quote:
Originally Posted by Turtle91 View Post
Using vh as a bottom margin won't hurt anything if it is not supported in compliant renderers...as you well know.


I know - Just use fall-back coding.
But why use vh for a bottom margin when you can use em and it will work in more places?
JSWolf is offline   Reply With Quote
Old 06-26-2025, 11:21 AM   #10
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 79,612
Karma: 145864263
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
Quote:
Originally Posted by Slevin#7 View Post
I don't know whether this specific solution works with Kindle formats, so you would have to try.

This approach won't split the question-answer segment into two sections, but will show the answer directly under each question. It relies on a checkbox and its :checked pseudo selector to toggle the visibilty of the answer:

HTML
Code:
<div class="question">
  <p>Is the sky blue?</p>

  <label for="checkbox-answer_1" class="toggle-answer">
    Click here to show/hide the answer.   
  </label>

  <!-- We have to place the checkbox outside the label element
         since otherwise targeting .answer wouldn't be possible.
         This requires an id to link the label to the checkbox. -->

  <input type="checkbox" id="checkbox-answer_1" class="checkbox-answer"/>

  <div class="answer">
    <p>Yes, the sky is blue.</p>
  </div>
</div>
CSS
Code:
.question {
  padding: 0.1em 1em;
  background-color: #eee;
}

.answer {
  visibility: hidden;
  background-color: #ddd;
}

.toggle-answer {
  cursor: pointer;
  /* prevent accidentally selecting */
  -webkit-user-select: none;
     -moz-user-select: none;
      -ms-user-select: none;
          user-select: none;   
}

/* hide the checkbox, not a must for functionality */
.checkbox-answer {
  position: absolute;
  top: -1000px;
  left: -6000px;
  width: 0;
  height: 0;
  opacity: 0;
}

.checkbox-answer:checked ~ .answer {
  visibility: visible;
}
Your toggle-answer CSS is all wrong. None of the code is ePub compliant. Also with your checkbox-answer CSS, your PX are way too large. If you don't know the screen size that's going to be used, thjen you have to code as if it's a small cell phone screen to a large screen.
JSWolf is offline   Reply With Quote
Old 06-26-2025, 11:44 AM   #11
Slevin#7
Enthusiast
Slevin#7 began at the beginning.
 
Posts: 38
Karma: 10
Join Date: May 2025
Device: iPad
Quote:
Originally Posted by JSWolf View Post
Your toggle-answer CSS is all wrong. None of the code is ePub compliant. Also with your checkbox-answer CSS, your PX are way too large. If you don't know the screen size that's going to be used, thjen you have to code as if it's a small cell phone screen to a large screen.
Can you please tell me, where the code is wrong? It passes the epub check and works well in Sigil, Calibre and other readers.

Regarding the px to hide the checkbox, it doesn't matter which size the screen has, it's just a big value to place the checkbox way out of the viewport. Values of -100/-100 should work as well, as long as there is no relative parent along the way up to the body element.
Slevin#7 is offline   Reply With Quote
Old 06-26-2025, 11:57 AM   #12
robertmchicago
Enthusiast
robertmchicago began at the beginning.
 
Posts: 30
Karma: 10
Join Date: Apr 2025
Device: none
Quote:
Originally Posted by Slevin#7 View Post
I don't know whether this specific solution works with Kindle formats, so you would have to try.

This approach won't split the question-answer segment into two sections, but will show the answer directly under each question. It relies on a checkbox and its :checked pseudo selector to toggle the visibilty of the answer:

HTML
Code:

Thanks for the codes!
I tested them on different apps.
In Sigil, they work very well.
In Kindle Previewer, the answer is hidden, but clicking does not show it.
In ADE 2.0, the answer is already visible (it doesn't hide).
In Kobo Desktop, the answer is hidden, but clicking does not show it.
I wish these codes worked in all apps the same way they work in Sigil.
Thanks again!
robertmchicago is offline   Reply With Quote
Old 06-26-2025, 12:07 PM   #13
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 79,612
Karma: 145864263
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
Quote:
Originally Posted by Slevin#7 View Post
Can you please tell me, where the code is wrong? It passes the epub check and works well in Sigil, Calibre and other readers.

Regarding the px to hide the checkbox, it doesn't matter which size the screen has, it's just a big value to place the checkbox way out of the viewport. Values of -100/-100 should work as well, as long as there is no relative parent along the way up to the body element.
Code:
.toggle-answer {
  cursor: pointer;
  /* prevent accidentally selecting */
  -webkit-user-select: none;
     -moz-user-select: none;
      -ms-user-select: none;
          user-select: none;   
}

/* hide the checkbox, not a must for functionality */
.checkbox-answer {
  position: absolute;
  top: -1000px;
  left: -6000px;
  width: 0;
  height: 0;
  opacity: 0;
}
for toggle-answer, none of code being used is ePub compatible. For checkbox-answer, your px values are way too large.
JSWolf is offline   Reply With Quote
Old 06-26-2025, 01:47 PM   #14
Turtle91
A Hairy Wizard
Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.
 
Turtle91's Avatar
 
Posts: 3,345
Karma: 20171571
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
Quote:
Originally Posted by JSWolf View Post
for toggle-answer, none of code being used is ePub compatible. For checkbox-answer, your px values are way too large.

It is ePub compatible if the renderer is ePub compliant. ePub renderers are required to ignore bad/non-supported css gracefully...

If ePubcheck doesn't complain about it, neither should you.


Do you happen to have a suggestion to make it work, rather than simply telling people it won't work??
Turtle91 is offline   Reply With Quote
Old 06-26-2025, 01:48 PM   #15
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,724
Karma: 24031401
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by robertmchicago View Post
I am making a reflowable EPUB 2 book using Sigil. The book also has about 400 questions and 400 answers, divided into two parts: one part for the questions, and one part for the answers.
You could also simply format your answers as footnotes in an epub3 book. If you use the generic footnote code in the Kindle Publishing Guidelines and the Apple Books Asset Guide 5.3.1, the answer will be shown as a popup.
Doitsu is offline   Reply With Quote
Reply

Tags
100vh, code, epub, margin, space


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
EPUB2 vs EPUB3 langshipley ePub 4 01-13-2023 06:47 PM
[Plugin] epub2 output Doitsu Plugins 11 12-01-2021 04:17 PM
Hiding endnotes after the last page of an epub2 HHJT ePub 52 02-27-2018 08:09 PM
epub3 to epub2 AlanHK Sigil 11 08-09-2017 05:06 AM
EPUB2 and the DOCTYPEgate roger64 ePub 21 07-18-2014 07:49 PM


All times are GMT -4. The time now is 09:50 AM.


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