The ThemeClassNames
object in your Docusaurus.
The ThemeClassNames
object in your Docusaurus project is a comprehensive structure for managing CSS class names associated with various components of your site. Each class name is organized by category (like page
, wrapper
, common
, docs
, and blog
), making it easier to apply consistent styling across your application. Here’s a detailed breakdown of each section:
1. Page Classes
These classes are specific to different types of pages on your site, particularly for blog and documentation pages.
-
Blog Pages:
blogListPage
: Use this class for the main blog listing page, where all blog posts are displayed.blogPostPage
: This class is for individual blog post pages. It allows you to style the content and layout of a single post.blogTagsListPage
: Apply this to the page that lists all available tags in the blog.blogTagPostListPage
: This is for the page that shows all posts associated with a specific tag.blogAuthorsListPage
: Use this for the page that lists all authors contributing to the blog.blogAuthorsPostsPage
: This targets pages that display all posts written by a specific author.
-
Docs Pages:
docsDocPage
: This class is for individual documentation pages, allowing you to style the layout and content of each doc.docsTagsListPage
: Similar to the blog, this is for listing all tags related to the documentation.docsTagDocListPage
: Use this for pages that show documentation associated with a specific tag.mdxPage
: This class is for pages rendered using MDX, allowing you to style MDX content specifically.
2. Wrapper Classes
These classes are meant to wrap main content areas, allowing for global styles to be applied to different sections of the site.
main
: This is a general wrapper for the main content area of your site. It typically contains all the primary content that users interact with.blogPages
: A wrapper specifically for blog-related pages. This can be used to apply styles that are consistent across all blog pages.docsPages
: Similar toblogPages
, but for documentation pages. Use it for styling that applies to all docs.mdxPages
: A wrapper for MDX pages, allowing you to apply specific styles for content rendered in this format.
3. Common Classes
These classes are used throughout your site and can be applied to various components, such as buttons and indicators.
editThisPage
: Style the "Edit this page" link/button, typically found in documentation pages.lastUpdated
: Use this for displaying the last updated timestamp on a page.backToTopButton
: Apply styles for a button that takes users back to the top of the page.codeBlock
: This class is for styling code blocks in your content.admonition
: Used for admonition elements, which highlight important information or warnings.unlistedBanner
: Style a banner that indicates the page is unlisted or not part of the main navigation.draftBanner
: A banner to indicate that the content is still in draft form.admonitionType(type: string)
: A function that generates class names based on the type of admonition (likeinfo
,warning
, etc.).
4. Docs-Specific Classes
These classes are specifically targeted for documentation content.
docVersionBanner
: Use this class for banners indicating the version of the documentation.docVersionBadge
: This can be used for badges that show the version of the doc in the UI.docBreadcrumbs
: For styling breadcrumbs that help users navigate back through documentation.docMarkdown
: This class is specifically for styling Markdown content within documentation pages.docTocMobile
: For styling the table of contents in mobile view.docTocDesktop
: Similar to the mobile version, but for desktop view.docFooter
: Style the footer area of documentation pages.docFooterTagsRow
: Use this for the row in the footer that displays tags associated with the document.docFooterEditMetaRow
: Style the metadata row in the footer, which often contains links to edit the document.docSidebarContainer
: A container for the sidebar in documentation pages.docSidebarMenu
: Style the menu items in the sidebar.docSidebarItemCategory
: For styling categories in the sidebar.docSidebarItemLink
: For individual link items in the sidebar.docSidebarItemCategoryLevel(level: number)
: A function to generate class names for sidebar categories based on their level (e.g., top-level, nested categories).docSidebarItemLinkLevel(level: number)
: Similar to the category function but for link items.
5. Blog-Specific Classes
These classes are used exclusively for styling elements in the blog section.
blogFooterTagsRow
: A row in the blog footer displaying associated tags.blogFooterEditMetaRow
: Style the footer metadata area, often for editing links or post information.
6. Page-Specific Classes
This section is for page-specific footer styles.
pageFooterEditMetaRow
: This class is used for the footer metadata row on regular pages, similar to the blog footer but more generic.
How to Use These Classes
To implement styles using these classes in your Docusaurus project, you can follow these steps:
-
Identify the Component: Determine which page or component you want to style (e.g., blog post, documentation page).
-
Add the Class to Your Component: In your JSX or MDX files, you can use the class names directly. For example:
<div className={ThemeClassNames.page.blogPostPage}>
<h1>My Blog Post</h1>
<p>This is the content of the blog post.</p>
</div> -
Style in Your CSS: In your CSS file (e.g.,
src/css/custom.css
), you can write styles targeting these class names:.blog-post-page {
background-color: #f9f9f9;
padding: 20px;
border-radius: 10px;
} -
Customize as Needed: Feel free to modify the styles and combine multiple classes to achieve the desired look and feel.
The theme-doc-markdown
class example
The theme-doc-markdown
class in Docusaurus is used to style the main content area where Markdown files are rendered. This class allows you to apply custom styles specifically to the content generated from your Markdown files, such as documentation pages. Here’s what you can do with the theme-doc-markdown
class and how to apply custom styles:
Customizing the Appearance of Markdown Content
-
Change Background and Text Color: You can modify the background color and text color of the Markdown content to match your site's theme.
/* src/css/custom.css */
.theme-doc-markdown {
background-color: #f0f0f0; /* Background color */
color: #333; /* Text color */
padding: 20px; /* Padding around content */
border-radius: 8px; /* Rounded corners */
} -
Style Headings: Customize the appearance of headings within your Markdown content.
.theme-doc-markdown h1,
.theme-doc-markdown h2,
.theme-doc-markdown h3,
.theme-doc-markdown h4,
.theme-doc-markdown h5,
.theme-doc-markdown h6 {
color: #005999; /* Heading color */
margin-top: 20px; /* Space above headings */
margin-bottom: 10px; /* Space below headings */
} -
Customize Links: Style links to enhance their visibility and interaction states.
.theme-doc-markdown a {
color: #007acc; /* Link color */
text-decoration: none; /* Remove underline */
}
.theme-doc-markdown a:hover {
color: #005999; /* Hover state color */
text-decoration: underline; /* Underline on hover */
} -
Style Code Blocks: Enhance the appearance of code blocks within your Markdown content.
.theme-doc-markdown pre {
background-color: #272c34; /* Background for code blocks */
color: #abb2bf; /* Text color for code blocks */
padding: 10px; /* Padding inside code blocks */
border-radius: 4px; /* Rounded corners for code blocks */
overflow: auto; /* Scroll for overflow */
}
.theme-doc-markdown code {
background-color: #f5f5f5; /* Inline code background */
color: #d63384; /* Inline code text color */
padding: 2px 4px; /* Padding for inline code */
border-radius: 4px; /* Rounded corners for inline code */
} -
Style Lists and Blockquotes: Customize lists and blockquotes to enhance readability and aesthetics.
.theme-doc-markdown ul,
.theme-doc-markdown ol {
margin-left: 20px; /* Indentation for lists */
padding-left: 20px; /* Padding for lists */
}
.theme-doc-markdown blockquote {
border-left: 4px solid #ccc; /* Left border for blockquotes */
padding-left: 20px; /* Padding inside blockquotes */
color: #666; /* Text color for blockquotes */
background-color: #f9f9f9; /* Background color for blockquotes */
}
Applying the Custom Styles
-
Create a Custom CSS File: Create a custom CSS file in your Docusaurus project, if you don't have one already. For example,
src/css/custom.css
. -
Add Your Styles: Add the desired styles to your custom CSS file.
-
Import the Custom CSS in Docusaurus: Ensure that your custom CSS file is imported in the
docusaurus.config.js
file.// docusaurus.config.js
module.exports = {
// Other configurations...
stylesheets: [
{
href: '/css/custom.css',
type: 'text/css',
},
],
};
Example
Here's a complete example of how you might customize the theme-doc-markdown
class:
/* src/css/custom.css */
/* Main content styling */
.theme-doc-markdown {
background-color: #f0f0f0;
color: #333;
padding: 20px;
border-radius: 8px;
}
/* Headings */
.theme-doc-markdown h1,
.theme-doc-markdown h2,
.theme-doc-markdown h3,
.theme-doc-markdown h4,
.theme-doc-markdown h5,
.theme-doc-markdown h6 {
color: #005999;
margin-top: 20px;
margin-bottom: 10px;
}
/* Links */
.theme-doc-markdown a {
color: #007acc;
text-decoration: none;
}
.theme-doc-markdown a:hover {
color: #005999;
text-decoration: underline;
}
/* Code blocks */
.theme-doc-markdown pre {
background-color: #272c34;
color: #abb2bf;
padding: 10px;
border-radius: 4px;
overflow: auto;
}
.theme-doc-markdown code {
background-color: #f5f5f5;
color: #d63384;
padding: 2px 4px;
border-radius: 4px;
}
/* Lists */
.theme-doc-markdown ul,
.theme-doc-markdown ol {
margin-left: 20px;
padding-left: 20px;
}
/* Blockquotes */
.theme-doc-markdown blockquote {
border-left: 4px solid #ccc;
padding-left: 20px;
color: #666;
background-color: #f9f9f9;
}
By following these steps, you can effectively use the theme-doc-markdown
class to customize the appearance of the main content rendered from Markdown files in your Docusaurus project.