Difficulty styling TOC content using CSS

Post here questions and problems related to editing and publishing DITA content.
Tomh94
Posts: 6
Joined: Mon Dec 18, 2023 6:46 pm

Difficulty styling TOC content using CSS

Post by Tomh94 »

Hello,

This forum has been a goldmine when it comes to solving my DITA to (mainly) PDF transformations in combination with using CSS to style the output. Now I encounter a problem for which I am unable to find a solution, even on this forum.

I am attempting to replicate the styling a customer uses for the TOC in their word manuals. More specifically, I am attempting to create more space between the chapter numbering and the chapter title, like in the image below.
image1.png
image1.png (144.58 KiB) Viewed 825 times
I am able to target the different map/topicrefs and thus, styling them. But when I move them the chapter number moves as well.
I have no succes with peuso elements like ::before and ::marker.
Any and all help is greatly appreciated!

Kind regards,
Tom
julien_lacour
Posts: 498
Joined: Wed Oct 16, 2019 3:47 pm

Re: Difficulty styling TOC content using CSS

Post by julien_lacour »

Hello,

You're right the <topicref> element includes both chapter number and title, to add a space you should use an deeper element in the structure, for example navtitle:

Code: Select all

*[class ~= "map/topicref"] *[class ~= "topic/navtitle"] {
  margin-left: 1em;
}
You can use your favorite browser to debug the CSS and see the actual structure, how the CSS is applied and the stylesheets order.

Regards,
Julien
Tomh94
Posts: 6
Joined: Mon Dec 18, 2023 6:46 pm

Re: Difficulty styling TOC content using CSS

Post by Tomh94 »

Hello Julien,

Thank you for your reply. That does indeed work... mostly. When the amount of chapters enters the double digits the chapters are nog longer aligned the way I want them to be, see the image below.
afbeelding.png
afbeelding.png (103.16 KiB) Viewed 794 times
Is there any way to prevent this from happening?

Again, thanks in advance for your help,

Kind regards,
Tom

PS: Thank you for the tip about debugging the css using a browser, will definitely be using that in the future
julien_lacour
Posts: 498
Joined: Wed Oct 16, 2019 3:47 pm

Re: Difficulty styling TOC content using CSS

Post by julien_lacour »

Hello,

In this case you need to set the args.css.param.title-layout parameter value to "table".
Then, you can set a width for each cell containing the chapter numbering:

Code: Select all

*[class ~= "map/map"][title-layout='table'] *[class ~= "map/topicref"][is-part] > *[class ~= "map/topicmeta"]:before,
*[class ~= "map/map"][title-layout='table'] *[class ~= "map/topicref"][is-chapter]:not([is-part]) > *[class ~= "map/topicmeta"]:before,
*[class ~= "map/map"][title-layout='table'] *[class ~= "map/topicref"][is-chapter]:not([is-part]) > *[class ~= "map/topicref"] > *[class ~= "map/topicmeta"]:before,
*[class ~= "map/map"][title-layout='table'] *[class ~= "map/topicref"][is-chapter]:not([is-part]) > *[class ~= "map/topicref"] > *[class ~= "map/topicref"] > *[class ~= "map/topicmeta"]:before,
*[class ~= "map/map"][title-layout='table'] *[class ~= "map/topicref"][is-chapter]:not([is-part]) > *[class ~= "map/topicref"] > *[class ~= "map/topicref"] > *[class ~= "map/topicref"] > *[class ~= "map/topicmeta"]:before {
  width: 1cm;
}
You can use any unit from the moment the chapter numbering fits in the given width.

Regards,
Julien
Tomh94
Posts: 6
Joined: Mon Dec 18, 2023 6:46 pm

Re: Difficulty styling TOC content using CSS

Post by Tomh94 »

Hello Julien,

Thanks again for your help. Your solution works but presents a new problem, one I vaguely remember seeing in a different forum post once.

I have set my numbering to "deep", instead of the default "shallow". I have figured out that this setting is the reason the following problem occurs:
The page numbering on the right side of the TOC is no longer correctly aligned when numbering is set to deep in combination with the parameter "args.css.param.title-layout" value set to "table", see the below image.
deep numbering.png
deep numbering.png (109.59 KiB) Viewed 718 times
Page numbers are indented at seemingly random places and the indentation also seems to be quite random.

When the numbering is set to default [shallow], this is the output:
default shallow numbering.png
default shallow numbering.png (104.29 KiB) Viewed 718 times
julien_lacour
Posts: 498
Joined: Wed Oct 16, 2019 3:47 pm

Re: Difficulty styling TOC content using CSS

Post by julien_lacour »

Hello,

I tested on my side using <oXygen/> XML Editor 26.0, build 2023100905, the CSS I gave you previously and deep numbering, the result is the following:
deep_toc.png
deep_toc.png (45.43 KiB) Viewed 701 times
Maybe you have other rules disrupting the TOC display: different fonts, margins, paddings, etc.

Regards,
Julien
Tomh94
Posts: 6
Joined: Mon Dec 18, 2023 6:46 pm

Re: Difficulty styling TOC content using CSS

Post by Tomh94 »

Hi Julien,

I decided to attempt to replicate your example.
1. I duplicated the DITA Map PDF - based on HTML5 & CSS scenario.
2. Changed the numbering to 'deep'.
3. Changed the args.css.param.title-layout parameter value to 'table'.
4. Added a new CCS file, containing only the CSS you gave me, with the exception of adding a background color for visual purposes.

Code: Select all

/* together with setting 'args.css.param.title-layout' parameter value to "table", this evens out the width of the chapter numbering */
*[class ~= "map/map"][title-layout='table'] *[class ~= "map/topicref"][is-part] > *[class ~= "map/topicmeta"]:before,
*[class ~= "map/map"][title-layout='table'] *[class ~= "map/topicref"][is-chapter]:not([is-part]) > *[class ~= "map/topicmeta"]:before,
*[class ~= "map/map"][title-layout='table'] *[class ~= "map/topicref"][is-chapter]:not([is-part]) > *[class ~= "map/topicref"] > *[class ~= "map/topicmeta"]:before,
*[class ~= "map/map"][title-layout='table'] *[class ~= "map/topicref"][is-chapter]:not([is-part]) > *[class ~= "map/topicref"] > *[class ~= "map/topicref"] > *[class ~= "map/topicmeta"]:before,
*[class ~= "map/map"][title-layout='table'] *[class ~= "map/topicref"][is-chapter]:not([is-part]) > *[class ~= "map/topicref"] > *[class ~= "map/topicref"] > *[class ~= "map/topicref"] > *[class ~= "map/topicmeta"]:before {
  width: 1cm;
  background-color: rgb(51, 255, 0);
}
Unfortunately I get the same problem, see the image below.
afbeelding.png
afbeelding.png (114.14 KiB) Viewed 698 times
I am using <oXygen/> XML Editor 25.1, build 2023042509

Any ideas what I might be missing/doing wrong?

Thanks again!
Last edited by Tomh94 on Fri Dec 22, 2023 5:02 pm, edited 3 times in total.
julien_lacour
Posts: 498
Joined: Wed Oct 16, 2019 3:47 pm

Re: Difficulty styling TOC content using CSS

Post by julien_lacour »

Hello,

I don't have <oXygen/> XML Editor 25.1, build 2023042509, only the last maintenance build 2023070306 but the problem doesn't seems to be present on this version.
Maybe you could try to update to this last maintenance build and see if the page numbers align.

Regards,
Julien
Tomh94
Posts: 6
Joined: Mon Dec 18, 2023 6:46 pm

Re: Difficulty styling TOC content using CSS

Post by Tomh94 »

Hello,

I have updated to oXygen editor 26.0, my colleagues have author 26.0 and we all still encounter the same problem.

Whenever the args.css.param.title-layout parameter value is set to "table", the numbering is set to 'deep' and the CSS contains the code you provided we get something like this:
afbeelding.png
afbeelding.png (100.08 KiB) Viewed 601 times
Even if the custom css file contains only your code and we use the standard oXygen template we get a wobbly column of page numbers on the right.

I have targeted the green ' ......X' part by changing :before to :after, but I cannot manage to meaningfully change its position. I had hoped I could just align those to the right side of the TOC but no luck...

Code: Select all

*[class ~= "map/topicref"] > *[class ~= "map/topicmeta"]::after,
*[class ~= "map/topicref"] > *[class ~= "map/topicmeta"] > *[class ~= "topic/navtitle"]::after{
  background-color: #77ca29;
}
I find it strange that you seemingly are able to get the right output, while we can't. Even with empty, clean css and scenario's.

Could you maybe try and test again while also marking the chapter number prefix with a colored background, like in my example?

Thanks again for your time!
julien_lacour
Posts: 498
Joined: Wed Oct 16, 2019 3:47 pm

Re: Difficulty styling TOC content using CSS

Post by julien_lacour »

Hello,

I added your CSS to my sample, and using <oXygen/> XML Editor 26.0, build 2023100905 I still obtain aligned numbers in TOC.
I tried to debug my CSS and opened the merged.html file in Author mode:

Code: Select all

*[class~='map/topicref'] > *[class~='map/topicmeta'] > *[class~='topic/navtitle']:after {
background-color : rgb(119 , 202 , 41) ;
}
*[class~='map/topicref']:not(*[scope='external']) *[class~='topic/navtitle']:after {
content : leader(".") target-counter(attr(href) , page) ;
}
The inspection only shown your custom rule and the default rule on the after block (displaying the leader and the page number).
You could try to check it on your side too and see if you have the same style.

If you have the same display, could you send us a small sample where this problem occurs at support@oxygenxml.com for analysis?

Regards,
Julien
Post Reply