开发者

Printing documents with sidenotes, position:relative and position:absolute

开发者 https://www.devze.com 2023-03-15 15:39 出处:网络
I\'m working on a web version of an old document, and it has sidenotes. I\'ve managed to get it looking right in Firefox and Chrome, but there\'s a problem with printing: the sidenotes are all jammed

I'm working on a web version of an old document, and it has sidenotes. I've managed to get it looking right in Firefox and Chrome, but there's a problem with printing: the sidenotes are all jammed together at the top of the first page (image).

I've put up the first section of the old document here, so that you can try it out yourself: http://www.dinkypage.com/117588. As you will see with Print Preview, the paragraph numbers and page numbers work fine (with only one minor problem), it's just the sidenotes that are causing a major problem.

I think the code is fairly easy to understand, but here's the most important snippet of the CSS style:

.sidenote, .widenote {
    position: absolute;
    left: 745px;
    margin-top: 12px;
    text-align: left;
    line-height: 1.17em;
    font-size: 12px;}
.sidenote {width: 200px;}
.widenote {width: 400px;}
.sidenote span, .widenote span {
    display: block;
    position: relative;
    text-indent: 5px;
    padding: 0px 0px 8px 0px}

I've m开发者_如何学运维essed with the position:relatives and the position:absolutes, but I can't get it to work properly. Any help would be appreciated. Thanks!

EDIT: I've put it up on jsfiddle, but it refuses to increment the page numbers for some reason: http://jsfiddle.net/KDzRp/


You need to specity "top" for ".sidenote, .widenote", FF and Chrome can determine the Top of your absolutely positioned element by it's appearance in the HTML, but older browsers (and apparently your printer) can not do so.

When using position:absolute always take care of both "hoziontal (left/right)" and "vertical (top/bottom)" position.

If you can not specify the exact top position of your site/wide notes, you need to wrap each page in a position:relative container and give top:0 to your sidenotes.:

<div class='page'>
    <p>...</p>
    <aside class='sidenote'>...</aside>
</div>

.page {position:relative;}
.sidenote {position:absolute; top:0; right:0; ...}

this way your sidenote will stick to the top of it's own section.

0

精彩评论

暂无评论...
验证码 换一张
取 消