Is it possible to restrict the width of an admonition? #7885
-
Here's what ChatGPT gave me:Yes, you can target only a specific admonition or a specific page by adding custom classes or using page-specific selectors in the CSS. Here’s how you can achieve this: 1. Target a specific admonition using a custom class:You can add a custom class to a specific admonition in your Markdown file. MkDocs Material allows you to specify a custom class for admonitions using the For example, you can add a class like !!! note "Custom Admonition"
This is a custom admonition with limited width.
:class: custom-width Now, in your /* Limit the width of admonitions with class 'custom-width' */
.custom-width {
max-width: 600px;
margin: 0 auto; /* Center the admonition */
} This will only apply the width limit to the admonition that has the 2. Target admonitions on a specific page:If you want to limit the width of an admonition on only one page, you can target it using the For example, if your page is called
This will ensure the style is applied only on the 3. Target a specific admonition on one page without custom classes:If you don’t want to manually add a custom class to each admonition, you can use the page-specific class and the general /* Limit width of all admonitions on a specific page */
body.page-my-page .admonition {
max-width: 600px;
margin: 0 auto;
} This will apply to all admonitions on that specific page ( Summary:
These methods allow you to fine-tune the styles without affecting other pages or admonitions across the whole site. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hello @MaximilianKohler, From the docs it says:
So in your case it wold be |
Beta Was this translation helpful? Give feedback.
Hello @MaximilianKohler,
the answer provided by ChatGPT with the
:class:
is a hallucination probably based on the Sphnix docs, however the admonitions in MkDocs are generated using the extension from Python Markdown:From the docs it says:
So in your case it wold be
!!! note custom-width "Custom Admonition"
The CSS looks fine.