2017-03-18 91 views
1

有沒有人遇到下面的問題?我的所有目錄的 首先看起來像這樣:到另一個頁面元素的HTML5鏈接導航到頁面頂部而不是指定元素

/root 
    index.html 
    /blog 
     /category 
     posts.html 
      /post 
      mypostname.html 

我用引導4.
我想從我的index.html導航至/blog/category/post/mypostname.html

div元素

我的index.html的代碼如下所示:

<a href="blog/category/post/mypostname.html#post-body-mg-1"> 
    <button class="btn btn-outline-warning">Czytaj więcej &hellip;</button> 
</a> 

代碼目的地頁:

<div id="post-body-mg-1">(it has content)</div> 

的問題是,它導航到博客頁面的頂部,而不是指定的div元素。當我把相似的鏈接放在posts.html頁面中時,點擊它可以毫無問題地導航到那個元素。


當我寫這樣的(注意斜線/ posts.html後),此鏈接:

<a href="blog/category/post/mypostname.html/#post-body-mg-1"> 
    <button class="btn btn-outline-warning">Czytaj więcej &hellip;</button> 
</a> 

它肯定的作品,並導航到指定的格但!它無法加載樣式表,因爲它使mypostname.html文件更深入目錄。 當我在樣式表的鏈接中添加更多級別的路徑(../)以匹配這個加深的目錄時,它會加載所有內容,但又會停止導航到指定的元素,這更加有趣!
它可能是bootstrap4的問題嗎?我懷疑它因爲它不涉及引導機制,是嗎?


請反饋我的答案結構,以及如果它不正確,因爲我是新的Stackoverflow。

回答

0

<a href="blog/dsp2017/post/mypostname.html#post-body-mg-1"> 
 
    <button class="btn btn-outline-warning">Czytaj więcej &hellip;</button> 
 
</a> 
 

 
<a href="blog/category/post/mypostname.html/#post-body-mg-1"> 
 
    <button class="btn btn-outline-warning">Czytaj więcej &hellip;</button> 
 
</a>

兩個環節是具有

dsp2017

有些事情要與不同?

+0

哦,因爲我從我的實際項目中複製這個,似乎忘記了將名稱更改爲通用名稱。 不幸的是,它與此無關。 我現在要編輯它,以避免更多的混淆。 – krisSzell

相關問題