2020-08-30 17:47:50 +03:00
|
|
|
# Setting up the header
|
|
|
|
|
2023-09-14 20:09:18 +03:00
|
|
|
Material for MkDocs' header can be customized to show an announcement bar that
|
2020-08-30 17:47:50 +03:00
|
|
|
disappears upon scrolling, and provides some options for further configuration.
|
2021-10-10 22:04:22 +03:00
|
|
|
It also includes the [search bar] and a place to display your project's
|
|
|
|
[git repository], as explained in those dedicated guides.
|
2020-08-30 17:47:50 +03:00
|
|
|
|
2021-10-10 22:04:22 +03:00
|
|
|
[search bar]: setting-up-site-search.md
|
|
|
|
[git repository]: adding-a-git-repository.md
|
2020-08-30 17:47:50 +03:00
|
|
|
|
|
|
|
## Configuration
|
|
|
|
|
|
|
|
### Automatic hiding
|
|
|
|
|
2023-09-14 20:09:18 +03:00
|
|
|
<!-- md:version 6.2.0 -->
|
|
|
|
<!-- md:feature -->
|
2020-08-30 17:47:50 +03:00
|
|
|
|
2021-10-10 22:04:22 +03:00
|
|
|
When autohiding is enabled, the header is automatically hidden when the
|
2021-02-02 22:51:42 +03:00
|
|
|
user scrolls past a certain threshold, leaving more space for content. Add the
|
2021-01-31 21:23:28 +03:00
|
|
|
following lines to `mkdocs.yml`:
|
2020-08-30 17:47:50 +03:00
|
|
|
|
|
|
|
``` yaml
|
|
|
|
theme:
|
|
|
|
features:
|
2020-09-19 16:49:05 +03:00
|
|
|
- header.autohide
|
2020-08-30 17:47:50 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
### Announcement bar
|
|
|
|
|
2023-09-14 20:09:18 +03:00
|
|
|
<!-- md:version 5.0.0 -->
|
|
|
|
<!-- md:flag customization -->
|
2021-10-03 21:28:52 +03:00
|
|
|
|
2020-08-30 17:47:50 +03:00
|
|
|
Material for MkDocs includes an announcement bar, which is the perfect place to
|
|
|
|
display project news or other important information to the user. When the user
|
|
|
|
scrolls past the header, the bar will automatically disappear. In order to add
|
2021-10-10 22:04:22 +03:00
|
|
|
an announcement bar, [extend the theme] and [override the `announce`
|
|
|
|
block][overriding blocks], which is empty by default:
|
2020-08-30 17:47:50 +03:00
|
|
|
|
|
|
|
``` html
|
2021-09-12 11:15:21 +03:00
|
|
|
{% extends "base.html" %}
|
|
|
|
|
2020-08-30 17:47:50 +03:00
|
|
|
{% block announce %}
|
2021-10-10 22:04:22 +03:00
|
|
|
<!-- Add announcement here, including arbitrary HTML -->
|
2020-08-30 17:47:50 +03:00
|
|
|
{% endblock %}
|
|
|
|
```
|
|
|
|
|
2021-10-10 22:04:22 +03:00
|
|
|
[extend the theme]: ../customization.md#extending-the-theme
|
|
|
|
[overriding blocks]: ../customization.md#overriding-blocks
|
2021-12-02 17:22:23 +03:00
|
|
|
|
|
|
|
#### Mark as read
|
|
|
|
|
2023-09-14 20:09:18 +03:00
|
|
|
<!-- md:version 8.4.0 -->
|
|
|
|
<!-- md:feature -->
|
|
|
|
<!-- md:flag experimental -->
|
2021-12-02 17:22:23 +03:00
|
|
|
|
|
|
|
In order to render temporary announcements that can be marked as read by the
|
|
|
|
user, a button to dismiss the current announcement can be included. Add the
|
|
|
|
following lines to `mkdocs.yml`:
|
|
|
|
|
|
|
|
``` yaml
|
|
|
|
theme:
|
|
|
|
features:
|
|
|
|
- announce.dismiss
|
|
|
|
```
|
|
|
|
|
|
|
|
When the user clicks the button, the current announcement is dismissed and not
|
|
|
|
displayed again until the content of the announcement changes. This is handled
|
|
|
|
automatically.
|
|
|
|
|
|
|
|
[Scroll to the top of this page][top] to see it in action.
|
|
|
|
|
|
|
|
[top]: #
|