Skip to content

Titleless custom containers #4928

@brawaru

Description

@brawaru

Is your feature request related to a problem? Please describe.

When using custom containers in Vitepress, they will automatically inherit the title based on the type of the container. You can override this by supplying title immediately after container opening, however, there is no option to get rid of title completely.

Describe the solution you'd like

It would be nice if there was an option to use containers without titles. Perhaps, if the title is set to -, then the title can be skipped, and a class applied to remove the extended padding from the top (although, the extended padding can probably be moved to a :has() selector, see below).

Example:

:::tip -

💡 This is a helpful tip.

:::
Screenshot of the custom container for the example that has no title and no excessive padding
:has() CSS changes

  .custom-block {
-   padding: 16px 16px 8px;
+   padding: 8px 16px;
  }

+ .custom-block:has(.custom-block-title) {
+   padding-top: 16px;
+ }

Describe alternatives you've considered

You can create custom containers yourself, like this:

<div class="custom-block tip" style="padding-top: 8px">

💡 This is a helpful tip.

</div>

However, this is not ergonomical, nor is it future-proof (What if those class names change? What if the padding changes?).

Additional context

The use case for this already exists within Vitepress docs:

<div class="tip custom-block" style="padding-top: 8px">
Just want to try it out? Skip to the [Quickstart](./getting-started).
</div>

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    themeRelated to the theme

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions