0

I want to print a html page in A4 size paper. I use this code: CSS

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;  
}
page[size="A3"] {
  width: 29.7cm;
  height: 42cm;
}
page[size="A3"][layout="portrait"] {
  width: 42cm;
  height: 29.7cm;  
}
page[size="A5"] {
  width: 14.8cm;
  height: 21cm;
}
page[size="A5"][layout="portrait"] {
  width: 21cm;
  height: 14.8cm;  
}
@media print {
  body, page {
    margin: 0;
    box-shadow: 0;
  }
}

HTML

<page size="A4"></page>

But I dont have the expecting result. A large gray outline is printed out of the text. Also I want to have the ability to print my page vertical or horizontialm

user8190974
  • 23
  • 1
  • 1
  • 6
  • Possible duplicate of [How to make a HTML Page in A4 paper size page(s)?](https://stackoverflow.com/questions/3341485/how-to-make-a-html-page-in-a4-paper-size-pages) – deg Sep 17 '17 at 09:39
  • Firstly I used those codes but nothing happen. – user8190974 Sep 17 '17 at 09:41

2 Answers2

1

A4 size is 210x297mm and you can use this:

html,body{
        height:297mm;
        width:210mm;
    }
0
body {
  background: rgb(204,204,204);
  margin: 0;
  padding: 0; 
}
kyun
  • 9,710
  • 9
  • 31
  • 66