Weekly Roundup

April may be the cruelest month, but here at Stillpoint Digital there's some good news — with a new month, comes a new roundup of this weeks most interesting #eprdctn-related articles.  Continue reading Weekly Roundup

Elements of Style: CSS for Ebooks

I originally published this post on Joel Friedlander's wonderful resource for self-publishers, TheBookDesigner.com

If HTML is the blueprint, showing how an ebook (or a web page) should be laid out, Cascading Style Sheets (CSS) are the interior design, saying how everything should look. While that may sound superficial, in fact learning to use CSS can have a profound impact on your ebook.

This is a somewhat complicated topic, so I am going to take three posts to cover it. This time round, I’m going to show you what CSS is and how to apply it. In the second post, I’m going to look at some of the different properties that you can use to define how your ebook looks. And in the last post, I’m going to talk about how to know which rules take precedence when.

CSS was created to define the presentation style to any XML document — but it's most common use is in conjunction with the HTML in web pages and, of course, in ebooks. It's what allows you to add color, to change fonts and (within reason) typefaces, to define where and how images display, and much more.

The Rule of Law

All CSS really comes down to is a series of rules that define how a particular element (or kind of element) will look when an ereader displays it.[1]

Each rule has two parts:

  1. A selector, which can be:
  • One or more type of HTML element (that is, any instance of a particular tag: <p>, <body>, <em>, etc.)
  • One or more class (that is, any elements that have been given the attribute class="whatever")
  • An element with a particular ID (that is, having the attribute id="whatever")
  1. A declaration — that is to say, one or more properties defining how the selector(s) should display

So here's an example from the stylesheet file Styles/Styles.css in the "White Robes" ebook that I linked to a couple of posts back:

h1, .Text-break {color:darkred;}

That's a lot simpler than it might at first look.

The part before the curly brackets ({}) marks the selector(s); there are two here, separated by a comma:

  • h1: If you look back to my last post, you'll see that h1 marks the top-level section head — usually a chapter title.
  • .Text-break: This is a class — the name of a particular style. You can tell because of the period at the beginning. [2]

Sometimes you see these selectors combined. I could have marked the second one p.Text-break, because in fact it's a style that I apply to whole paragraphs — in the case of "White Robes," paragraphs that contain a single em-dash to be used as a separator between sections of text. But I don't have to say what kind of element the class needs to be applied to (although that can sometimes be useful). By leaving the p off before the period, I could apply the same rule to other kinds of elements, if I wanted.

The part inside the curly brackets is the actual rule — the declaration. It contains a color property that tells the ereader to turn sections that match those selectors dark red. Simple, right?
Since there can be more than one rule per declaration, each declaration needs to end in a semicolon:

h1, .Text-break {color:darkred;font-weight:bold;}

I'll get into more detail on some of the various rules that you care about in another post — sorry, this one is already complicated enough!

Location, location, location

Now there are three places you can place a CSS rule:

  1. Inline as part of an HTML tag
  2. In a <style> tag inside the <head> at the top of the HTML file
  3. In a linked CSS file, either in the ebook itself or on the open internet

Inline Style

If you want to apply a CSS style to just one HTML tag, you can do it inline by adding a style attribute to an HTML tag.

For example, if I were to want to center a particular paragraph, I could add style="text-align:center" to the <p> tag, like so:

<p style="text-align:center;">

(Remember: those quotes must be "straight," not “smart” or “curly.”)

Likewise, if I were to want to make a particular section (or <span>) of text in Garamond, I would do this:

Here is a phrase displayed as <span style="font-family:Garamond;">Garamond</span>.

Now, that would only work if Garamond were actually installed on the ereader or embedded in the ebook, so I added the generic serif, which tells the ereader to use its default serif typeface.

Notice that I don't use a selector when using the style attribute. Since the declaration is inside a tag, it's clear what the rule refers to. Make sense?

<style> Tag

You can do all sorts of wonderful things when you apply styles inline — but when you do, they will only apply to those tags where they're added, and they will always apply there, until you search through and change them. (I know, setting all of the text to orange Comic Sans seemed like such a good idea!)

So how can you make your CSS styles more powerful and easier to edit?

Use global styles. These are the equivalent of the styles used in word-processing and page-layout apps — changing the style changes every part of the document to which the style has been applied.

There are two ways to do this in any HTML document — including one of the files that makes up your ebook.

The first is to add a <style></style> block to your file. As I said, it is placed in the <head> section of the file, and would look something like this:

<html>
<head>
<style type="text/css">
h1, .Text-break {color:darkred;}
p {color:black;}
#Green {color:green;}
</style>
</head>
<body>
<h1>This header is red</h1>
<p>This paragraph is black.</p>
<p class="Text-break">This paragraph is red!</p>
<p id="Green">This paragraph is green.</p>
</body>
</html>

Notice that the <style> tag should always include the attribute type="text/css." That tells the ereader that this is standard CSS.

That would display this way:

Now, notice that in addition to styling the <p> element black and the h1 element and the Text-break class red, I styled the paragraph with the id attribute Green as… you know, green.

Just as a period before the name tells us that the selector is a class, the pound sign (#) before the name lets us know that the selector is an ID. So in the style tag above, that looked like this:

#Green {color:green;}

By having a single set of declarations in the header, you can save yourself the trouble of adding the same rule over and over again, and then having to change every instance of it if you decide, for example, to make the .Text-break blue instead of red.

CSS Style Sheet

The third way to add style to your ebook’s HTML pages is to create one or more style sheets and link to them in the <head> section of each page.

This works just like having a <style></style> section at the top of your chapter — except the rules will apply not just in one file, but in all of them. This is especially important if you’re working on a longer, multi-chapter ebook.

First create an empty text file with the file type .css. In the “White Robes” ebook, I created the file Styles.css in the directory/folder Styles:

You can also create the file in whatever editing software you’re using. In Sigil, go to the File menu, and then select Add>Blank Stylesheet.

The contents of the file looks almost exactly like the <style type="text/css"> section I showed you above. Here’s the style sheet from “White Robes”:

Some of those rules might make sense to you; most of them won’t. Don’t worry; the next post will be a primer on some of the most important rules and properties.

Oh — notice that each property in the declaration section (the part inside the curly brackets) is on its own line. Just as in HTML, those line breaks are meaningless. What separates one property from the next is, as I said above, a semicolon. So Sigil puts each rule on its own line for no reason other than making it easier to read.

Also, something important: in CSS, the rule closer to the bottom has priority. So notice in the third rule that says that a whole bunch of different kinds of HTML elements, including the body element will have no margin, no padding, and no border width.[3]

Then the very next rule sets the padding (that is, the space inside the edge of the element before words and images can show up) to five pixels.[4]

Because the second <body> declaration is closer to the bottom, it takes priority. The rule means that every page in the ebook will have a thin white space around the outside edge of the screen or window.

(Prioritization — which rules apply in which cases — is a complicated issue. I will get to it in the third and final post on CSS.)

Okay, so you’ve got a style sheet. But if it’s not linked from the XHTML file, those files won’t show up at all!

So you’ve got to add a <link> element to the <header> block of each XHTML file (that is, chapter) in your ebook to which you want to style sheet to apply.

The link element looks like this:

<link href="../Styles/Styles.css" rel="stylesheet" type="text/css"/>

That tells the ereader to look for the file Styles.css in the directory Styles (just where I put it); it tells the ereader that the relationship between the files is that Styles.css is a style sheet for the current XHTML file, and that’s it’s a CSS file.

Once you’ve added that link, all of the formatting that you’ve defined in the sheet will be applied to your now-beautiful chapters.

So, that’s our quick introduction to CSS.

Next time, I’ll run through some of the most important properties that you can define using CSS, and after that, I’ll finish up with a quick overview of style priorities.

Like this post? Sign up for my newsletter, and you’ll get my ebook An Indie Publisher’s Intro to Ebooks for free!


[1] Remember: an element is a block of HTML, usually set off at the beginning and end by open and close tags, like this: <tag>[stuff]</tag>

[2] By the way, you can apply multiple classes to a single element — just separate them with a space: class="red small-caps”. Two things to keep in mind: First, the later class will take precedence, so if I added a class attribute with the values red and blue, the text would display as blue, since the blue class came last. Second, some older ereaders don’t handle multiple classes well (I’m looking at you, old-style Kindle). I usually try to stick to one class per element for that reason.

[3] You’ll often see a rule like this at (or near) the top of a style sheet; it’s called zeroing out or initialization. It makes sure that there isn’t any carry-over from the ereader’s default settings or other styles.

[4] Yeah, it looks like it’s stuttering; the four 5px values apply to the top, right, bottom, and left padding, in that order. That allows you to customize the spacing between elements quite a lot.

Weekly Roundup – 6 Fresh Topics in Ebook Publishing

Don't call it a comeback! Here's the second installment in our now weekly roundup of interesting articles in the world of eBook publishing.  Continue reading Weekly Roundup – 6 Fresh Topics in Ebook Publishing

Speaking in Code: Ebook HTML basics

This post originally appeared on Joel Friedlander's wonderful site, TheBookDesigner.com.

If, as I keep saying, an ebook is just a website a box, then in order to know how to get in and edit your ebook, you’re going to want to know some HTML. However you choose to work on the file, knowing the basic building blocks is essential in creating a finished  product that presents your book to its best advantage.

 

When we talk about HTML, we’re actually talking about two separate things:

Continue reading Speaking in Code: Ebook HTML basics

Weekly Roundup: 7 Interesting Articles on eBook Publishing

As a matter of principal (both personal and professional) I spend quite a bit of my time keeping up to date with what's new in the eBook publishing world. Having built up a relatively substantial feed to scroll through, it recently occurred to me that I'm not the only one who could benefit from a list of new ePublishing articles  to peruse while I'm going about my day.

With that in mind, I've decided to start publishing a weekly list of recent articles I think are important, interesting, innovative, etc. Here are this week's choices:

Continue reading Weekly Roundup: 7 Interesting Articles on eBook Publishing

Timekeeper is on its way!

Copies of Timekeeper are on their way to all our Kickstarter backers! Thanks again for your support. If you don't receive yours in a reasonable amount of time, please contact us.

Two down, one to go!  Continue reading Timekeeper is on its way!

Special Offer: Buy Timekeeper, Get Timepiece Free!

Heather Albano's Timekeeper: A Steampunk Time-Travel Adventure has hit the shelves! It's available now in ebook or print form at your favorite store!

And since we know you might want to read book #1 in the Keeping Time series, Timepiece, before reading book #2, we thought we'd extend your chance to get the book free! Continue reading Special Offer: Buy Timekeeper, Get Timepiece Free!

Launch your summer reading with a free time-travel adventure!

Looking for a great way to launch your summer reading?

Last month, Heather Albano's Timepiece: A Steampunk Time-Travel Adventure hit #1 on Amazon, Kobo, iBooks, Barnes and Noble, and Google Play in the Steampunk genre! It was part of a two-day promotion that was more successful than we could ever have hoped.

Well, in case you missed it, here's your chance to get the book free! Continue reading Launch your summer reading with a free time-travel adventure!

David Kudler on The Hero’s Journey® in Sacramento

CWC SacramentoStillpoint author and publisher David Kudler will be giving a talk this Saturday at the California Writers Club Sacramento on the subject of "The Enduring Hero’s Journey®: How to Make your Writing Compelling and Memorable."

Kudler, who has worked with Joseph Campbell Foundation since 1999, will talk about Campbell's concept of The Hero's Journey®, as it was laid out in his seminal book The Hero with a Thousand Faces. Kudler edited the 2008 edition of the book. He will look at the ways in which the Hero Journey can serve as a blueprint for creating an enduring, transformative story.

Location: Cattlemens Restaurant, 12409 Folsom Blvd., Rancho Cordova, CA
Date/Time: Saturday May 20, 2017, 11:00 AM-1:00 PM
Website: http://www.cwcsacramentowriters.org/2017/luncheon-david-kudler/

“The Hero’s Journey®” is a registered trademark of Joseph Campbell Foundation (JCF.org) and is used with permission

Giveaway! WIn a copy of Timepiece

Sign up now on Goodreads for a chance to win a copy of Timepiece: A Steampunk Time-Travel Adventure by Heather Albano!

Goodreads Book Giveaway

Timepiece by Heather Albano

Timepiece

by Heather Albano

Giveaway ends May 08, 2017.

See the giveaway details at Goodreads.

Enter Giveaway

You only THINK you know what happened at Waterloo

The real story involved more monsters. And a lot more time travel.

It’s 1815, and Wellington’s badly-outnumbered army stares across the field of Waterloo at Napoleon’s forces. Desperate to hold until reinforcements arrive, Wellington calls upon a race of monsters created by a mad Genevese scientist 25 years before.

It’s 1815, and a discontented young lady sitting in a rose garden receives a mysterious gift: a pocket watch that, when opened, displays scenes from all eras of history. Past…and future.

It’s 1885, and a small band of resistance fighters are resorting to increasingly extreme methods in their efforts to overthrow a steampunk Empire whose clockwork gears are slick with its subjects’ blood.

Are these events connected?

Oh, come now. That would be telling.


“Waterloo and time travel are made for each other and Heather Albano has done a wonderful job of giving us a delightful cast of characters, tasked with stitching together the proper nineteenth century while fending off several monstrous alternatives. Propulsive adventure with historical insight.” – Kim Stanley Robinson, Red Mars and 2312

Austen, meet Waterloo. When a genteel 1815 heiress is given a strange watch, she time-travels to an 1885 England where history has gone hideously wrong. Now she has to change it back to what it “should” have been—and that never works out well, does it? A delicious supercharged blend of steampunk and the Napoleonic Wars, with a thrill on every page.” — Sarah Smith, The Vanished Child

If Jane Austen and Mary Shelley had locked H. G. Wells in a dungeon and revised his wildest work, the result would have been something like this rollicking steampunk time-travel adventure that still manages to be a comedy of manners. Albano’s delightful characters confront the not only monsters and killer robots, but their own divided loyalties between personal happiness and the fate of their country.Ken Schneyer, The Law & the Heart

The human face of digital publishing

%d bloggers like this: