I want to do something like the following:
@page :left{
h1 {text-align: left;}
}
@page :right {
h1 {text-align: right;}
}
but this syntax doesn't work in CSS. How do I change text alignment based on whether the page is left or right?
I want to do something like the following:
@page :left{
h1 {text-align: left;}
}
@page :right {
h1 {text-align: right;}
}
but this syntax doesn't work in CSS. How do I change text alignment based on whether the page is left or right?
If setting the alignment for all text on the page is acceptable, this should work:
@page :left {text-align: left;}
@page :right {text-align: right;}
If the page contains one h1 element, plus one or more other elements, you could put the h1 in the page header, see this related question.
I haven't tested it by i believe you can do this:
@page :left h1 {text-align: left;}
@page :right h1 {text-align: right;}
According to https://www.w3.org/TR/css3-page/#margin-property-list, the syntax:
@page :left {
h1 { text-align: left; }
}
@page :right {
h1 { text-align: right; }
}
is correct; however, as said by others, currently there is no browser support for @page
, and the latest release of PrinceXML doesn't support text-align
either.
This means that, by now, it can't be done.
However, PrinceXML supports margin
in page margin contexts. So, if one can afford pushing text using static margins e.g.:
@page :left{
h1 { margin-right: 10000em; } // We all know 10000em equals to infinity.
}
@page :right {
h1 { margin-left: 10000em; }
}
then this is an OK kludge.
Edit: In fact, PrinceXML does support text-align
, but not for running headers; apparently it only works with generated string-content.