Forum How do I...?

conditional formatting based on odd/even page

dglane
I have done conditional formatting (e.g. alternate shading) of lines. However, how can I perform conditional formatting of content based on whether the page is odd or even? For instance, I may want to do a "float: right;" if it is a left page and a float: left;" if it is a right page.

Thanks.
mikeday
You can use "float: inside" and "float: outside", which are relative to the two page spread.
dglane
OK, perhaps I shouldn't have used "float" as the example. What about aligning text left/right depending on the odd/even page?
csant
You could try "text-align: inside" or "text-align-outside". There are several CSS properties that take care of paged styling - use "thinking in spreads" https://www.princexml.com/doc-prince/#thinking-in-spreads as a starting point.
dauwhe
you can use outside or inside as values of text-align.
dglane
Pardon me. I have been using various CSS references which do not have "outside" or "inside". In fact, I don't see those anywhere I look (except this site) but indeed that works. Thanks.
csant
Not in fact a spec yet, but a "living idea": https://figures.idea.whatwg.org/ CSS Figures.
Also, Prince has several extensions to CSS, useful for paged media. Paged media CSS is still quite a work in progress, and you'll see that all formatters have their own extensions.
howcome
Prince14 supports many of the ideas from the CSS Figures draft. Here are some examples on how to use the float-defer-* properties for page spreads:
https://www.princexml.com/howcome/2021/guides/float/#spreads