Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS @page doesn't display content in @top-center, @bottom-right, etc

Tags:

html

css

printing

I'm trying to generate a print-ready HTML file and therefore started working with CSS @page and everything around it. One big problem I'm facing is that I can't manage to display page numbers using @bottom-right and all similar solutions. Do you know if there could be a general reason behind it (like it's deprecated, etc.), as I've tested even the simplest solutions like:

@page {
  @bottom-right {
    content: counter(page);
  }
}

and still nothing seems to make the pagination or any other content appear.

like image 730
Dani Dimitrov Avatar asked Feb 09 '18 17:02

Dani Dimitrov


People also ask

How do I put text in the top right corner CSS?

The top-right text should be set to position: absolute; top: 0; right: 0 . The bottom-right text should be set to position: absolute; bottom: 0; right: 0 .

How do you center text with position fixed?

You basically need to set top and left to 50% to center the left-top corner of the div. You also need to set the margin-top and margin-left to the negative half of the div's height and width to shift the center towards the middle of the div.

What does @page do in CSS?

The @page at-rule is a CSS at-rule used to modify different aspects of a printed page property. It targets and modifies the page's dimensions, page orientation, and margins. The @page at-rule can be used to target all pages in a print-out, or even specific ones using its various pseudo-classes.

How do you change the position of text in HTML?

We can change the alignment of the text using the text-align property. We can align the text in the center, Left, Right. The text alignment can be done with CSS(Cascading Style Sheets) and HTML Attribute tag. Note: The left alignment of the text is default.


1 Answers

What are you using to render this? A lot of browsers don't have proper support for print CSS, so it might be better to use something specifically built for it, like weasyprint.

like image 161
Moira Jones Avatar answered Oct 25 '22 00:10

Moira Jones