View Full Version : Top Margin in epub


penguintri
05-06-2010, 04:51 PM
I'm having trouble setting the margin at the top of my screen on an epub. The text is to close to the edge and can have a shadow over it. ( I'm using a prs 300 btw).

I have tried putting in a

@page { margin-top: 2.5em; margin-bottom: 1em }

and changing different calibre styles but I can't seem to manage to change the top margin.

Cheers for any help.

DaleDe
05-06-2010, 05:31 PM
em requires a font and no font is defined in @page time. You need other units like pixels, or points.

penguintri
05-06-2010, 05:48 PM
Ah cheers.

I tried using

@page { margin-top: 12pt; margin-bottom: 12pt }

and it didn't work! I'm not sure if I'm using it right, I'm just inserting it at the top of the css after the

@namespace h "http://www.w3.org/1999/xhtml"; that is in the css.

Jellby
05-07-2010, 06:27 AM
Make sure the css file is actually being used in the book, and that there is no other @page rule overriding your settings.

HarryT
05-08-2010, 08:51 AM
Why do you want to define your page margins in "em" units. Do you honestly want your margins to be bigger if the user increases the font size?

penguintri
05-08-2010, 12:32 PM
How would I make sure the book is using the css for the top margin? This is the css I have for my book.

@namespace h "http://www.w3.org/1999/xhtml";
@page { margin-top: 22pt; margin-bottom: 1pt }
.calibre {
widows: 1;
orphans: 1;
display: block;
font-size: 1em;
margin-bottom: 0;
margin-left: 0;
margin-right: 0;
margin-top: 0;
page-break-before: always
}
.calibre1 {
border-bottom: 0;
border-top: 0;
display: block;
margin-bottom: 0;
margin-top: 0;
padding-bottom: 0;
padding-top: 0;
text-indent: 1.5em
}
.calibre2 {
display: block;
font-size: 1.6em;
font-weight: bold;
margin-bottom: 0.67em;
margin-left: 0;
margin-right: 0;
margin-top: 0.67em
}
.calibre3 {
display: block;
margin-bottom: 0;
margin-left: 0;
margin-right: 0;
margin-top: 0;
padding-bottom: 0;
padding-left: 0;
padding-right: 0;
padding-top: 0;
page-break-before: always
}
.calibre4 {
border-bottom: 0;
border-top: 0;
display: block;
margin-bottom: 0;
margin-left: 0;
margin-right: 0;
margin-top: 0;
padding-bottom: 0;
padding-top: 0;
text-align: justify;
text-indent: 1em
}
.calibre5 {
display: block;
font-size: 1.6em;
font-weight: bold;
margin-bottom: 0.67em;
margin-left: 0;
margin-right: 0;
margin-top: 0.67em;
text-align: center
}
.calibre6 {
widows: 1;
orphans: 1;
font-size: 1.25em;
border: 0;
border-bottom: 0;
border-top: 0;
display: block;
margin-bottom: 0;
margin-left: 0.28em;
margin-right: 0.28em;
margin-top: 0.01em;
padding-bottom: 0;
padding-left: 0;
padding-right: 0;
padding-top: 0;
text-align: justify;
text-indent: 1em
}
.calibre7 {
display: block;
font-size: 1.5em;
font-weight: bold;
margin-bottom: 0.83em;
margin-left: 0;
margin-right: 0;
margin-top: 0.83em;
text-align: center
}
.calibre8 {
border-bottom: 0;
border-top: 0;
display: block;
margin-bottom: 0;
margin-left: 1em;
margin-right: 1em;
margin-top: 0;
padding-bottom: 0;
padding-top: 0;
page-break-after: always;
text-align: justify;
text-indent: 1.5em
}
.calibre9 {
border-bottom: 0;
border-top: 0;
display: block;
margin-bottom: 0;
margin-top: 0;
padding-bottom: 0;
padding-top: 0;
page-break-after: always;
text-indent: 1.5em
}
a {
color: inherit;
text-decoration: inherit;
cursor: default
}
a[href] {
color: blue;
text-decoration: underline;
cursor: pointer
}

I didn't realise that em scaled with the font size. I just used it as this is the way calibre default set my margins. What would an approximate equivalent to 0.28em in pt be?

DaleDe
05-08-2010, 02:18 PM
I didn't realise that em scaled with the font size. I just used it as this is the way calibre default set my margins. What would an approximate equivalent to 0.28em in pt be?

How can we know? An em is the width of the letter M in whatever point size that the letter M is in while a point size is 1/72 of an inch.

Dale

HarryT
05-08-2010, 02:47 PM
I didn't realise that em scaled with the font size. I just used it as this is the way calibre default set my margins. What would an approximate equivalent to 0.28em in pt be?

Yes, that's the whole point of "em" units - the fact that they scale with the font. You use them in situations where you want something to "match up" with the font size. Eg, for indenting poetry, I use 1em for each "level" of indentation, because that's something that you want to change with the font size. As Dale notes, 1em is the width of a letter "M" in the current font.

For something like page margins, though, you probably want to either use a fixed physical width, such as 10pt, or you want to make them a percentage of the page size, eg 5%.

charleski
05-08-2010, 08:37 PM
Ah, the real problem here is one of calibre's slightly annoying quirks.

Calibre places an @page rule in the header of each html file, and this overrides any @page rule in the css.

The solution is to edit all your html files and remove the style that calibre has inserted at the top. It will look like this:

<style type="text/css">
@page { margin-bottom: 5.000000pt; margin-top: 5.000000pt; }</style>
Once this has gone, then you can control the top and bottom margins from the @page rule in the css file.

Be aware that ADE seems to add a small top margin of its own (even with no top margin, there is still a small gap at the top) - this is on the PRS-505, other implementations may differ. I find a top margin of 9pt works well, and visually matches the 12pt right and left margins I use.