Jekyll - Automatically highlight current tab in menu bar

后端 未结 12 1026
鱼传尺愫
鱼传尺愫 2020-12-22 15:34

I am using github to host a static site and Jekyll to generate it.

I have a menu bar (as

    ) and would like the
  • correspo
12条回答
  •  忘掉有多难
    2020-12-22 15:42

    The navigation of your website should be an unordered list. To get the list items to lighten up when they are active, the following liquid script adds an 'active' class to them. This class should be styled with CSS. To detect which link is active, the script uses ‘contains’, as you can see in the code below.

    
    

    This code is compatible with all permalink styles in Jekyll. The ‘contains’ statement succesfully highlights the first menu item at the following URL’s:

    • getting-started/
    • getting-started.html
    • getting-started/index.html
    • getting-started/subpage/
    • getting-started/subpage.html

    Source: http://jekyllcodex.org/without-plugin/simple-menu/

提交回复
热议问题