【问题标题】:Dropdown box appearing incorrectly on GitHub Pages built with Jekyll使用 Jekyll 构建的 GitHub 页面上的下拉框出现错误
【发布时间】:2017-05-08 07:20:15
【问题描述】:

我使用 Jekyll 构建的 GitHub Pages 站点在推送到 GitHub 时无法正确显示我的导航栏。当使用 'jekyll serve' 在本地构建时,它可以正常工作,如下所示:

但是,当推送到 github 时,标题不可见,并且似乎链接显示在下拉框上方:

在本地,我有 Jekyll 3.4.3,与 github 上列出的相同,以前我的网站正常显示(本地与在线相同),但在中断几个月后,我似乎无法让它再次正确显示.我对 Jekyll 不是很有经验,因为这是我第一次尝试它,但我确实有一些其他的 Web 开发经验。

任何建议将不胜感激。

navbar.html

<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
    <div class="container-fluid">
        <button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
        </button>
<!--            <form class="navbar-search pull-right" 
action="http://google.com/search" method="get">
{% if site.safe %}
            <input type="hidden" name="q" value="site:{{ site.url | remove_first:'http://' }}">
{% else %}
            <input type="hidden" name="q" value="site:{{ site.url | domain_name }}">
{% endif %}
            <input type="text" name="q" class="input-medium search-query" placeholder="Search">
        </form> -->
        <div class="nav-collapse collapse">
            <ul class="nav">
{% for node in site.navbar_list %}
{% if node.name == page.group %}{% assign active = 'active' %}
{% else %}{% assign active = nil %}{% endif %}
{% if node.dropdown %}
                <li class="dropdown dropdown-container {{ active }}">
                    <a class="dropdown-link" href="{{ site.baseurl }}{{ node.link }}">{{ node.name }}</a>
                    <a class="dropdown-toggle" data-toggle="dropdown" href="#">{{ node.name }}<b class="caret"></b></a>
                    <ul class="dropdown-menu">
    {% for sub in node.dropdown %}
                        <li><a href="{{ site.baseurl }}{{ sub.link }}">{{ sub.name }}</a></li>
    {% endfor %}
                    </ul>
                </li>
{% else %}
                <li class="{{ active }}">
                    <a href="{{ site.baseurl }}{{ node.link }}">{{ node.name }}</a>
                </li>
{% endif %}
{% endfor %}
            </ul>
        </div><!--/.nav-collapse -->
    </div>
</div>

样式.css

/* title of the site */
#header {
    height: 80px;
}
#header hgroup {
    position: absolute;
    top: 10px;
    left: 20px;
}
#header h1 {
    margin: 0;
    font-size: 1.75em;
    font-weight: bold;
}
#header h2 {
    color: #ccc;
    margin: 0 0 4px 16px;
    line-height: 0.8;
    font-size: 1.0em;
    font-weight: normal;
}
#header a,
#header a:hover,
#header a:visited {
    text-decoration: none;
}

/* header.html: navbar */
.navbar-fixed-top {
    margin-bottom: 20px;
    position: static;
}
.navbar-fixed-top .navbar-inner {
    padding: 0;
    border-top: 1px solid #d4d4d4;
    border-bottom: 1px solid #d4d4d4;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.067);
}
.navbar .nav > .active > a,
.navbar .nav > .active > a:hover,
.navbar .nav > .active > a:focus {
    box-shadow: none;
}
.navbar .btn-navbar {
    margin-bottom: 5px;
}
.lt-ie9 .collapse {
    overflow: visible; /* removed from 2.1.1, but still IE need this */
}

/* header.html: dropdown container */
.navbar .nav > li.dropdown-container {
    position: relative !important;
}
.navbar .nav > li.dropdown-container .dropdown-link {
    position: absolute !important;
    top: 0;
    left: 0;
    z-index: 1;
}
.navbar .nav > li.dropdown-container .caret {
    margin-left: 1.5em;
}
.navbar .nav > li.dropdown-container .dropdown-link + .dropdown-toggle {
    z-index: 0;
}

【问题讨论】:

  • 你能尝试放弃与协议无关的 hrefs //...min.css 并使用 https://...min.css
  • 对不起,我不明白你的意思,site.baseurl 是用 http:// 定义的,但我没有在我的帖子中包含它,因为据我所知链接工作正常。是否有其他位置我应该包​​括这个来解决我的问题?
  • 我的意思是如何将//netdna.bootstrapcdn.com/bootswatch/2.3.2/cerulean/bootstrap.min.css 之类的链接转换为https://netdna.bootstrapcdn.com/bootswatch/2.3.2/cerulean/bootstrap.min.css
  • 谢谢,但我仍然不知道在哪里进行此更改 - 你能从我的代码中举一个例子吗?或者它可能在我的仓库中的位置?
  • _includes/head.html

标签: html css jekyll github-pages


【解决方案1】:

要解决您的问题,您需要将 style.css 文件从 _includes\css 复制到 assets\css 并将其重命名为 site.css(因为您在 assets\css 文件夹中已经有 style.css)然后您必须添加链接到_includes\head.html如下:

{% endcase %}
<link rel="stylesheet" href="{{ site.baseurl }}/assets/css/site.css">
<link rel="stylesheet" href="{{ site.baseurl }}/assets/css/style.css">

<!-- Font Awesome -->

【讨论】:

  • 谢谢!我只想提醒其他可能也有这个问题的人:我之前尝试过 cutting 并粘贴,但我的网站不会在本地构建,但 copying 允许我的网站在本地构建,现在已修复在 GitHub 上。再次感谢!
猜你喜欢
  • 2022-12-10
  • 2021-08-25
  • 1970-01-01
  • 2018-06-23
  • 2018-12-11
  • 2018-04-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-19
相关资源
最近更新 更多