In the most recent versions of Kindlegen, top margins on <div> elements are ignored. Older versions of Amazon’s conversion tool routinely ignored bottom margins, so we all programmed ourselves to use top margins for vertical spacing. Now, divs with top margins display without any space to separate them from previous content.
The fix is simple. Add a bottom margin to the paragraph or other HTML element preceding a div. When would you need to do this? The most common scenario would be preceding a div used to organize blocks of poetry or lyrics. Margin bottom is honored in both Mobi 7 and KF8 versions created by Kindlegen.
Your ePub version will not be adversely affected by adjusting paragraph margins preceding divs, so you could do it in the original ePub file or just for a Kindle ePub source file.
In practice, you might add a CSS selector (named anything you want) for paragraphs preceding divs, where there should be a blank line:
p.blank1bot {margin-bottom: 1em;}
If you have consecutive divs that need spacing, add a bottom margin:
div.blank1bot {margin-bottom: 1em;}
David Gatwood says
The problem with your workaround for Amazon’s bug is that it doesn’t work at page boundaries. Consider a drop cap where the glyph is raised above the normal paragraph bounds. You typically use a top margin to ensure that if the paragraph appears at the top of the page, the entire paragraph gets pushed down to accommodate the extra space for the upper part of the drop cap glyph.
If Kindle ignores the top margin, then when the paragraph appears at a page boundary, the drop cap gets clipped. No amount of bottom padding or margin on the element above it can solve that problem.
This is why it is vitally important for eBook readers to be fully compliant with web standards. Every time a company like Amazon decides to go off on their own and try to “fix” our content, they invariably break any content that is doing anything even slightly interesting typography-wise. There is simply no excuse for that. We have standards for a reason, and Amazon needs to learn how to follow them.
Araby Greene says
Your point is well taken. I don’t use drop caps in Kindle books because I’ve yet to see a book in which they don’t look like a ransom note.
In other situations, the consequences of a page break in the flow of a book preceding a div tag aren’t so dire. Since I use a valid ePub as my foundation document, the file is split at every required page break to ensure the break and proper top margins on all devices. Formatting for Kindle is still painful. Amazon had a golden opportunity to switch to ePub with the Kindle Fire and they chose to go off on a different track with KF8. That decision seems unsustainable for the long haul.