美文网首页博客教程Hexo
Hexo博客next主题添加Fork me on GitHub

Hexo博客next主题添加Fork me on GitHub

作者: wiliam_wiliam | 来源:发表于2017-02-11 19:54 被阅读708次

    在网上浏览博客时经常看到页面的右上角或左上角有一个fork me on github的按钮,本文将介绍如何实现。

    1、效果展示

    右上角截图


    rightright

    左上角截图


    leftleft

    2、实现

    2.1、样式挑选

    点我跳转 挑选你自己喜欢的样式。

    2.2、next主题实现

    打开文件:hexo博客根目录\themes\next\layout\_layout.swig 找到如下代码块

    <div class="{{ container_class }} {% block page_class %}{% endblock %} ">
        <div class="headband"></div>
    
    

    添加自己喜欢的样式后结果如下

     <div class="{{ container_class }} {% block page_class %}{% endblock %} ">
        <div class="headband"></div>
     
     <a target="_blank" href="https://github.com/wiliam2015">![Fork me on GitHub](https://camo.githubusercontent.com/365986a132ccd6a44c23a9169022c0b5c890c387/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f7265645f6161303030302e706e67)</a>
    
    

    访问你的本地服务测试看看修改的效果吧。

    2.3、小屏幕不显示fork me on github

    按照上面的步骤当屏幕缩小后还会显示fork me on github图标,但这不是我想要的,我希望在大屏下显示,小屏后就不显示了。方法如下:
    修改文件hexo博客根目录\themes\next\layout\_layout.swig 找到如下代码块

    <html class="{{ html_class | lower }}">
    <head>
      {% include '_partials/head.swig' %}
      <title>{% block title %}{% endblock %}</title>
    
    

    添加如下代码,结果如下

    <head>
      {% include '_partials/head.swig' %}
      <title>{% block title %}{% endblock %}</title>
      <style>
      .forkme{
     display: none;
     }
      @media (min-width: 768px) {
     .forkme{
     display: inline;
     }
      }
      </style>
    </head>
    
    

    最后在2.2节添加的代码块上套上div加上class就行了,如下

    <div class="forkme">
     <a target="_blank" href="https://github.com/wiliam2015">![Fork me on GitHub](https://camo.githubusercontent.com/365986a132ccd6a44c23a9169022c0b5c890c387/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f7265645f6161303030302e706e67)</a>
     </div>
    
    

    最后在试试效果达到自己的想要的了

    相关文章

      网友评论

        本文标题:Hexo博客next主题添加Fork me on GitHub

        本文链接:https://www.haomeiwen.com/subject/joyoittx.html