简体   繁体   English

为根目录中的页面工作时,文件夹中的页面的 Bootstrap 下拉菜单损坏。 两组 php_include 相同的外部头文件

[英]Bootstrap dropdown menu broken for pages in folder while working for pages in root. Both groups php_include the same external header file

I run some of the web stuff at work on the side, not exceptionally experienced at this stuff.我在工作中运行一些网络东西,在这方面没有特别的经验。 I don't know what element of the process I've gone through has caused the hiccup so if you bear with me, I'll try and explain in-depth.我不知道我所经历的过程中的哪些因素导致了打嗝,所以如果你能忍受我,我会尝试深入解释。

Recently our site (basic bootstrap template) has begun expand out from just a few pages, and to stay on top of things I opted to pull the header and footer files out into their own includes folder, and use...最近我们的网站(基本引导模板)已经开始从几页扩展出来,为了保持最重要的状态,我选择将页眉和页脚文件拉到它们自己的包含文件夹中,并使用...

<!--Header include-->
<?php $path = $_SERVER['DOCUMENT_ROOT'] . "/includes/"; include ( $path . 'header.html' ); ?>

...for easier management. ...为了更容易管理。 Went through the site and stripped out old code and changed page extensions to php (and now began testing site on MAMP).The structure of the site is 75% of pages living in root, 25% living in a folder called services.浏览该站点并删除旧代码并将页面扩展名更改为 php(现在开始在 MAMP 上测试站点)。该站点的结构是 75% 的页面位于根目录中,25% 位于名为 services 的文件夹中。 All pages pull the same header.html So far so good.所有页面都使用相同的 header.html 到目前为止一切顺利。

The problem arrises when I test the site.当我测试网站时出现问题。 All pages that live in root (public_html) work as expected, the nav drop down menu contained in the header works fine.位于 root (public_html) 中的所有页面都按预期工作,标题中包含的导航下拉菜单工作正常。 But when you click into any of the pages that live in /services/ the dropdown (and only the dropdown), breaks.但是,当您单击位于 /services/ 中的任何页面时,下拉列表(并且只有下拉列表)会中断。 By breaks, I mean that a dropdown should appear on mouse hover over and it doesn't.通过中断,我的意思是鼠标悬停时应该出现一个下拉菜单,但它没有。 All of the other CSS, the theme, the code for a picture slider, works ok.所有其他 CSS、主题、图片滑块的代码都可以正常工作。 It's just this one element of the nav bar that breaks for these pages that live in the /services/ folder.对于位于 /services/ 文件夹中的这些页面,这只是导航栏的这一元素。

I compared the elements of a working page and a broken page by inspecting them firefox, and this is the only place I can see any differences..我通过检查 firefox 比较了工作页面和损坏页面的元素,这是我唯一能看到任何差异的地方。

On a working page, the working dropdown html shows as...在工作页面上,工作下拉 html 显示为...

ul class="dropdown-menu bold" style="display:none;"

With CSS rules of...使用 CSS 规则...

element {
    display: none;
}
.navbar .nav li .dropdown-menu {
    z-index: 1000;
}
header ul.nav li ul {
    z-index: 1000;
    margin-top: 20px;
}
.bold {
    font-weight: 900;
}
.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0px;
    z-index: 1000;
    display: none;
    float: left;
    min-width: 180px;
    padding: 0px;
    margin: 2px 0px 0px;
    list-style: outside none none;
    background: none repeat scroll 0% 0% #343434;
    box-shadow: none;
    border-right: 2px solid #302F2F;
    border-width: medium 2px 2px;
    border-style: none solid solid;
    border-color: -moz-use-text-color #302F2F #302F2F;
    -moz-border-top-colors: none;
    -moz-border-right-colors: none;
    -moz-border-bottom-colors: none;
    -moz-border-left-colors: none;
    border-image: none;
}
.dropdown-menu {
    border-radius: 0px;
}
.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0px;
    z-index: 1000;
    display: none;
    float: left;
    min-width: 160px;
    padding: 5px 0px;
    margin: 2px 0px 0px;
    list-style: outside none none;
    background-color: #FFF;
    border: 1px solid rgba(0, 0, 0, 0.2);
    border-radius: 6px;
    box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.2);
    background-clip: padding-box;
}
ul ul, ul ol, ol ol, ol ul {
    margin-bottom: 0px;
}
ul ul, ul ol, ol ol, ol ul {
    margin-bottom: 0px;
}
ul, ol {
    padding: 0px;
    margin: 0px 0px 10px 25px;
}
ul, ol {
    padding: 0px;
    margin: 0px 0px 10px 25px;
}
li {
    line-height: 1.6em;
}
li {
    line-height: 20px;
}
.nav {
    list-style: outside none none;
}
body {
    font-family: "Open Sans",sans-serif;
    font-size: 14px;
    font-weight: 400;
    line-height: 1.6em;
    color: #656565;
}
body {
    font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
    font-size: 14px;
    line-height: 20px;
    color: #333;
}
html {
    font-size: 100%;
}

The broken page(s) shows html of...损坏的页面显示...的 html

<ul class="dropdown-menu"></ul> <<< I think this might be a red flag??

and CSS of....和...的CSS

element {
}
.navbar .nav li .dropdown-menu {
    z-index: 1000;
}
header ul.nav li ul {
    z-index: 1000;
    margin-top: 20px;
}
.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0px;
    z-index: 1000;
    display: none;
    float: left;
    min-width: 180px;
    padding: 0px;
    margin: 2px 0px 0px;
    list-style: outside none none;
    background: none repeat scroll 0% 0% #343434;
    box-shadow: none;
    border-right: 2px solid #302F2F;
    border-width: medium 2px 2px;
    border-style: none solid solid;
    border-color: -moz-use-text-color #302F2F #302F2F;
    -moz-border-top-colors: none;
    -moz-border-right-colors: none;
    -moz-border-bottom-colors: none;
    -moz-border-left-colors: none;
    border-image: none;
}
.dropdown-menu {
    border-radius: 0px;
}
.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0px;
    z-index: 1000;
    display: none;
    float: left;
    min-width: 160px;
    padding: 5px 0px;
    margin: 2px 0px 0px;
    list-style: outside none none;
    background-color: #FFF;
    border: 1px solid rgba(0, 0, 0, 0.2);
    border-radius: 6px;
    box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.2);
    background-clip: padding-box;
}
ul ul, ul ol, ol ol, ol ul {
    margin-bottom: 0px;
}
ul ul, ul ol, ol ol, ol ul {
    margin-bottom: 0px;
}
ul, ol {
    padding: 0px;
    margin: 0px 0px 10px 25px;
}
ul, ol {
    padding: 0px;
    margin: 0px 0px 10px 25px;
}
li {
    line-height: 1.6em;
}
li {
    line-height: 20px;
}
.nav {
    list-style: outside none none;
}
body {
    font-family: "Open Sans",sans-serif;
    font-size: 14px;
    font-weight: 400;
    line-height: 1.6em;
    color: #656565;
}
body {
    font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
    font-size: 14px;
    line-height: 20px;
    color: #333;
}
html {
    font-size: 100%;
}

(I can manually change the broken dropdown in firefox inspect to element { display:inline } and the dropdown reappears, with working links to the other pages.) (我可以手动将 firefox 检查中损坏的下拉菜单更改为 element { display:inline } 并且下拉菜单重新出现,并带有指向其他页面的工作链接。)

Overall, I can't understand why this is happening.总的来说,我无法理解为什么会发生这种情况。

  • All of the other CSS is working on the broken pages, so the links to that location must work.所有其他 CSS 都在处理损坏的页面,因此指向该位置的链接必须有效。
  • All pages share the same header.html which uses the same html to create the working dropdowns.所有页面共享相同的 header.html,它使用相同的 html 来创建工作下拉列表。
  • All CSS is called individually at the start of each page in the head (not in the header.html file).所有 CSS 在每个页面的开头单独调用(不是在 header.html 文件中)。
  • If all pages look at the same header file, and they all point to the same CSS, how am I getting different results?如果所有页面都查看同一个头文件,并且它们都指向同一个 CSS,我如何得到不同的结果?

Thanks,谢谢,

Found the answer to this a while ago and I figured I'd update.不久前找到了这个答案,我想我会更新。 The javascript that animates the nav bar was written out and contained in the footer with relative links to the js folder, which hadn't been updated when the pages were moved into the services folder.为导航栏设置动画的 javascript 已写出并包含在页脚中,并带有指向 js 文件夹的相对链接,当页面移入 services 文件夹时,该文件夹尚未更新。 So the animations would fail because the javascript files couldn't be located.因此动画将失败,因为无法找到 javascript 文件。

Fixed this by making the footer as its own file in an includes folder with explicit links to the js folder from there, then used a php document root include (same as the code above) to bring it into the other pages.通过将页脚作为自己的文件放在包含文件夹中,并从那里显式链接到 js 文件夹,然后使用 php 文档根包含(与上面的代码相同)将其引入其他页面,从而解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM