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:

enter image description here

desired result:

enter image description here

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>

revised fiddle demo

more information:


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -