Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to declare a div in @page @top-left

Tags:

html

css

How do I declare that a DIV should be displayed in top-left corner of every page and not in its relative position.

I have a div like:

<div id=header>Document</div>

and I would like to display it on every page in top left corner using css like:

@page {
    size: 8.5in 11in;
    margin: 0.25in;
    border: thin solid black;
    padding: 1em;


     @top-left {
        content: ???? ;
      }
}

Thank you.

like image 875
Micor Avatar asked May 03 '10 19:05

Micor


People also ask

How do I move a div to the top left?

Well, that's because you have the parent div set to display:flex; The div your wanting to move is a flex item. To move the div continue using flex styles. Look back to the styles set on the parent div and use justify-content:end; to position the text on the right. Or use justify-content:start; to position on the left.

How do I place a div at the top of the page?

If position: absolute; or position: fixed; - the top property sets the top edge of an element to a unit above/below the top edge of its nearest positioned ancestor. If position: relative; - the top property makes the element's top edge to move above/below its normal position.


2 Answers

I realise that this question is a bit old, but for anyone like me who comes here searching for a way to do this, it is possible using CSS3 running elements: http://www.w3.org/TR/2007/WD-css3-gcpm-20070504/#running1

In this example, the header is hidden from view in all media types except print. On printed pages, the header is displayed top center on all pages, except where h1 elements appear.

<style>
  div.header { display: none }
  @media print {
  div.header {
    display: block;
    position: running(header);
  }
  @page { @top-center { content: element(header, last-except) }}
</style>
...
<div class="header">Introduction</div>

<h1 class="chapter">An introduction</div>
like image 74
YetAnotherMatt Avatar answered Oct 13 '22 20:10

YetAnotherMatt


Doesn't

#header {
   position: fixed;
   top: 0;
   left: 0;
}

work? See Printing Headers. Also, have a look at the W3C specification of position: fixed.

EDIT: if I read the CSS 3 specs concerning Margin Boxes well enough, together with the CSS 2.1 specs about the content property, I don't think you can embed a <div> from your page into the contents of a Margin Box, alas.

like image 21
Marcel Korpel Avatar answered Oct 13 '22 21:10

Marcel Korpel