【问题标题】:How can I put github's stars in Navbar using Docusaurus v2如何使用 Docusaurus v2 将 github 的星星放在导航栏中
【发布时间】:2021-06-14 17:53:12
【问题描述】:

我想放一个图标,请能做的人解释一下我可以在哪个文件中做以及如何做?

themeConfig: {
    navbar: {
      title: 'graphql-go/graphql',
      logo: {
        alt: 'My Site Logo',
        src: 'img/GraphQL_Logo.png',
      },      
      items: [
        {
          href: '/docs/tutorial-basics/overview',
          label: 'Docs',
          position: 'left',
        },
        // {to: '/blog', label: 'Blog', position: 'left'},
        {
          href: 'https://github.com/graphql-go/graphql',
          label: 'GitHub',
          position: 'right',
        },
      ],                   
    },    

【问题讨论】:

  • 你能详细说明你的问题吗?
  • 请描述发生了什么。你甚至没有发布一个问题,只是一些看起来像 JSON 的东西。
  • @luis 你为什么要删除看似尝试的代码?

标签: javascript reactjs docusaurus


【解决方案1】:

您想在顶部导航栏中的文本之前添加一个图标吗?最简单的方法是使用 ::before 和 ::after 选项创建一个 CSS 类。在该 css 中添加一个图标,例如使用 FontAwesome、Material 或 svg。然后在您的 docusaurus.config.js 文件中调用该 css。

例如:

themeConfig: {
    navbar: {
      title: 'graphql-go/graphql',
      logo: {
        alt: 'My Site Logo',
        src: 'img/GraphQL_Logo.png',
      },      
      items: [
        {
          href: '/docs/tutorial-basics/overview',
          label: 'Docs',
          position: 'left',
          className: 'navbar-icon-menu',
        },
        // {to: '/blog', label: 'Blog', position: 'left'},
        {
          href: 'https://github.com/graphql-go/graphql',
          label: 'GitHub',
          position: 'right',
        },
      ],                   
    },   

navbar-icon-menu 的 css 具有基于悬停、之前、之后的选项,以最匹配您想要显示的内容。只是一个示例,我们将以下内容用于社区图标。我们使用它来代替标签,但您可以调整并执行相同操作以同时显示图标和标签。很像在标签后显示向下箭头的下拉 CSS。

.navbar-community-menu:after {
  transition: opacity 0.2s;
  content: "";
  width: 24px;
  height: 24px;
  display: flex;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white' width='24px' height='24px'%3E%3Cpath d='M0 0h24v24H0z' fill='none'/%3E%3Cpath d='M20 2H4c-1.1 0-1.99.9-1.99 2L2 22l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zM6 9h12v2H6V9zm8 5H6v-2h8v2zm4-6H6V6h12v2z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  margin-right: 12px;
}

.navbar-community-menu:hover:after {
  opacity: 0.5;
}

.navbar-community-menu:after, .navbar-community-link:after {
  border-style: none !important;
  margin-left: -5px !important;
}

希望能提供一些想法!

【讨论】:

  • 这个答案太棒了。非常感谢。
猜你喜欢
  • 1970-01-01
  • 2022-11-27
  • 2020-10-13
  • 2020-10-08
  • 1970-01-01
  • 2017-11-05
  • 1970-01-01
  • 1970-01-01
  • 2023-03-23
相关资源
最近更新 更多