9

I am creating an ebook for Amazon's Kindle in HTML, and then later use KindleGen to convert it into the Kindle's MOBI version.

The problem I am currently having is with custom bullets for nested unordered lists that I am using for the ebook's Table of Contents. Initially I was using an image in the list-style-image property to create a custom bullet. This was the CSS I was using:

ul.customBullet
{
    list-style-image: url('images/bulletPointImage.png');
    margin:1.3em;
}

And this was the html:

<ul class ="customBullet">
<li><b><h3>Text 1<b></h3></li> <!-- 1st tier -->
       <ul class="customBullet">
         <li><h4><b>2:<b></h4> <1-- 2nd tier -->
             <ul class="customBullet">
                <li><h6>Text 3</h6> <!-- 3rd tier -->
                    <ul class="customBullet">
                       <li><h3><a href="#chap1"> Text</a></h3></li> <!-- 4th tier -->
                    </ul>


                </li> 
            </ul>
        </li>
        <li ><b>3: <b></li>
        <li ><b>4: <b></li>
        <li ><b>5: <b></li>
        <li ><b>6: <b></li>
        <li><b>7: <b></li>

       </ul>
</ul>

I was having problems with aligning the bullets with the text. The text appeared one line below the bullet and a little to the left and not alongside as it should (in Firefox). When I previewed the MOBI created with KindleGen in KindlePreviewer, the image of the bullet was coming out tiny (and not proportional to the image file) and the same problem of the bullet not positioned in the same line as the text.

Also, the bullets appear differently in each of the different kindle models (Kindle Paperwhite, Kindle Fire, etc.), the size of the image varied and with different sort of spacing between the bullet and the text.

I then read somewhere online that Kindle does not support the list-style-image tag. Kindle's official supported CSS tags also do not include it. So I created a simple bulleted list without the CSS but with the same html code above. The problem is the same with the spacing. And different shaped bullets appear on each tier. For example a hollow circular one on the first, a squarish one on the second and so on.

So, my question is , is there a way (any lines of code) to make streamlined bullets in html for kindle's ebook without all these variations in different versions, and also without all these unneeded space insertions, and a proper sort of positioning. Bullets that stay the same no matter which version of kindle is being used. Hope I have explained myself properly.

1 Answer 1

7

There are a few things going on here. The spacing issue is likely being caused by the presence of block elements inside list elements—the headers are probably getting bumped onto their own line, apart from the start of the list item. If you're starting with the toc.xhtml of an epub file, you'll need to lose any elements inside the Table of Contents list (which must be in a <nav>) other than <span>, <a>, or <ol>. You've got a couple other minor problems that are probably from typing stuff in here, but to hit them quickly:

  • The closing <b> tags don't have a "/", making them opening tags
  • The first list item ends before the list inside it begins
  • The first <b> ends before the <h3> containing it ends

Try out the following:

<nav id="toc" epub:type="toc">
    <ol class ="customBullet">
        <li class="tier1"><a href="item1.xhtml">Item</a> <!-- 1st tier -->
            <ol class="customBullet">
                <li class="teir2"><a href="item1.xhtml#part1">Sub-item</a> <!-- 2nd tier -->
                    <ol class="customBullet">
                        <li class="teir3"><a href="item1.xhtml#part1_1">Sub-sub-item</a> <!-- 3rd tier -->
                            <ol class="customBullet">
                                <li class="teir4"><a href="item1.xhtml#part1_1_1">Sub-sub-sub-item</a></li> <!-- 4th tier -->
                            </ol>
                        </li> 
                    </ol>
                </li>
            </ol>
        </li>
        <li>Item</li>
        <li>Item</li>
        <li>Item</li>
        <li>Item</li>
        <li>Item</li>
    </ol>
</nav>

You could as easily give the class definition to each <ol>, and then have the CSS point to ol.tier3 li { color: blue; } or whatever styling you want— might be easier to read the code that way.

Hope that's useful!

10
  • Thanks so much for this. That seemed to have gotten the more weirder spaces solved ! The text still appears displaced one line down of the bullet, should I work that out with margins and padding ?
    – QPTR
    Commented Mar 9, 2014 at 5:52
  • That's strange--the text shouldn't be displaced at all. You're certain there are no elements inside the <li> other than the <a>? I would suggest against trying to move the text up a line with negative margins or anything--that will almost certainly not end well: various devices will inevitably treat that stuff just differently enough to make it look a shambles. The old KF7 format, for example, doesn't support negative margins at all.
    – Tom
    Commented Mar 10, 2014 at 8:23
  • Actually, I am sorry, I should have been more precise. It comes out perfect with an ordered list, but I wanted to use a custom image for bullets so I tried this same code with an unordered list while including an image for a custom bullet.
    – QPTR
    Commented Mar 11, 2014 at 8:55
  • 1
    I haven't tried this, so I don't know for sure if it'll work or not, but you might try something like <li><span class="image" /><a>Text</a></li> with a corresponding span.image { background-image: image.jpg } in the CSS. That said, images in the TOC seem a little strange. What is it that you're trying to do? EDIT: The other thing to do, if images are a must, is to create a file purely for the graphical TOC, and leave the toc.xhtml and toc.ncx as the logical TOCs only.
    – Tom
    Commented Mar 18, 2014 at 6:39
  • 1
    The toc.nxc is the logical TOC for epub 2.0.1; the toc.xhtml is the logical TOC for epub 3.0. The toc.xhtml is also intended to be the graphical TOC, but it has a number of limitations (like only allowing <li>, <a>, and <span> tags) that mean that really graphically intensive works will sometimes still require a graphical TOC file (such as the cookbook I've been working on lately). As far as expanding and collapsing goes: most reading systems will do that automatically if you've nested your TOC as illustrated above.
    – Tom
    Commented Mar 18, 2014 at 7:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.