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.

Anthon
  • 7,621
  • 3
  • 22
  • 56
QPTR
  • 693
  • 1
  • 7
  • 14

1 Answers1

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!

Tom
  • 4,638
  • 2
  • 16
  • 33
  • 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 Mar 11 '14 at 08:55
  • Hello Tom, I just created an xhtml practice file for this and was wondering if its possible to create a custom bullet using the ol tag if an ul tag is not allowed (I looked around and it seems like its not). Or if its not possible does that mean there is no way one could use a custom image bullet for an ebook's table of contents ? – QPTR Mar 18 '14 at 06:33
  • 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 `
  • Text
  • ` 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 Mar 18 '14 at 06:39
  • Ah, thanks so much! Will try using that tag! Mostly wanna include images for aesthetic reasons, also I want to do this thing where I can expand/collapse one of the sub-headings (might chuck that idea out if its not possible in kindle) . Are images usually not appropriate in a table of contents file ? Could you please explain the graphical TOC part, I am kind of confused, as far as I've read isn't toc.ncx the only file that acts as a logical TOC ? I thought toc.xhtml was the one that appeared to the user at the beginning, can it be used as a logical TOC ? – QPTR Mar 18 '14 at 06:59
  • 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 `
  • `, ``, and `` 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 Mar 18 '14 at 07:05