Topic on Project:Support desk

Table of contents custom formatting

8
Summary last edited by Clump 18:19, 8 October 2020 3 years ago
.tocless #toc { border: none; background: none; }
Evolution and evolvability (talkcontribs)

Is there away to also alter TOC formatting (e.g. no border or background) by adding something to a wiki's Common.css? My css is definitely nowhere near good enough to attempt it. It is just for aesthetic reasons when used in WikiJournal articles (example), so not vital, but it would still be much appreciated.

AhmadF.Cheema (talkcontribs)
/* Remove border and background from all TOCs */
#toc {
    border: none;
    background: none;
}

To apply this CSS only for specific TOCs, use the following in your MediaWiki:Common.css,

.tocless #toc {
    border: none;
    background: none;
}

And in your article, include the TOC using the following code,

<div class="tocless">
__TOC__
</div>
Evolution and evolvability (talkcontribs)

Thanks! I'll test out the commons.css version on Wikiversity!

Evolution and evolvability (talkcontribs)

Sorry to reopen, just one additional related question:

Is it possible to easily use the CSS to left-align the "Contents [hide]" title?

AhmadF.Cheema (talkcontribs)

Include the following in your MediaWiki:Common.css,

.tocless #toc #toctitle, .toc #toctitle, #toc .toctitle, .toc .toctitle {
	text-align: left;
}

By-the-way, for minor .CSS changes, browser developer tools are very useful. In your browser, pressing Ctrl+Shift+C opens up a select tool which can be used to select and inspect any webpage element and take a look at all the .CSS rules and classes which define that element.

Evolution and evolvability (talkcontribs)
AhmadF.Cheema (talkcontribs)

Yes, I've been keeping an eye on the new TOC, looks well in context.

Also, taking a look at your discussion on MediaWiki talk:Common.css, you should know that you can see the potential changes of CSS rules in real-time through browser developer tools, without the need to actually change any MediaWiki:Common.css code.

Evolution and evolvability (talkcontribs)

Ahhh, I've had a play-around with the chrome Ctrl+Shift+C function. Really useful! I may have to start using div 'id's.

I've finally managed to get the TOC to stick during scrolling for the page top in the published articles. Still can't quite prevent the text overlapping on mobile though. Still a work in progress.