css3 - Flexbox centering within paper-css A4 page -
i'm writing a4 paper in html/css paper-css i'm having trouble centering (https://css-tricks.com/centering-css-complete-guide/#both-flexbox).
current result:
desired result:
https://jsfiddle.net/askhflajsf/x7sjrzy4/
@page { size: a4 } .frontpage { display: flex; justify-content: center; align-items: center; } .frontpage > * { text-align: center; } .frontpage footer { align-self: flex-end; } <link href="https://cdnjs.cloudflare.com/ajax/libs/paper-css/0.2.3/paper.css" rel="stylesheet"/> <body class="a4"> <section class="sheet padding-10mm frontpage"> <h1>logo centered horizontally/vertically</h1> <footer>footer centered horizontally pushed bottom vertically</footer> </section> </body>
the problem flex container set flex-direction: row (by default).
that means you're flex items horizontally aligned, creating 2 columns. content in each item cannot invade column space of sibling, centering horizontally on page not possible.
a better method use flex-direction: column. aligns items vertically.
then use justify-content: space-between pin items top , bottom.
then, add single , invisible pseudo-element serve flex item, forces heading vertical center.
@page { size: a4 } .frontpage { display: flex; justify-content: space-between; /* adjusted */ align-items: center; flex-direction: column; /* new */ } .frontpage::before { /* new */ content: ''; } .frontpage > * { text-align: center; } <link href="https://cdnjs.cloudflare.com/ajax/libs/paper-css/0.2.3/paper.css" rel="stylesheet"/> <body class="a4"> <section class="sheet padding-10mm frontpage"> <h1>logo centered horizontally/vertically</h1> <footer>footer centered horizontally pushed bottom vertically</footer> </section> </body> more information:


Comments
Post a Comment