How to make a HTML Page in A4 paper size page(s)?

前端 未结 15 2025
有刺的猬
有刺的猬 2020-11-22 16:30

Is it possible to make a HTML page behave, for example, like a A4-sized page in MS Word?

Essentially, I want to be able to show the HTML page in the browser, and out

15条回答
  •  天命终不由人
    2020-11-22 17:15

    I saw this solution after searching at google, search for "A4 CSS page template" (codepen.io). It shows an A4 (A3,A5, also portrait) sized area in the browser, using the tag. Inside this tag the content is shown, but absolute position is still with respect to browser area.

    body {
      background: rgb(204,204,204); 
    }
    page {
      background: white;
      display: block;
      margin: 0 auto;
      margin-bottom: 0.5cm;
      box-shadow: 0 0 0.5cm rgba(0,0,0,0.5);
    }
    page[size="A4"] {  
      width: 21cm;
      height: 29.7cm; 
    }
    page[size="A4"][layout="portrait"] {
      width: 29.7cm;
      height: 21cm;  
    }
    @media print {
      body, page {
        margin: 0;
        box-shadow: 0;
      }
    }
    A4
    A4 portrait

    This works for me without any other css/js-library to be included. Works for current browsers (IE, FF, Chrome).

提交回复
热议问题