使用<a> tag - href value

时间:2015-12-30 09:37:12

标签: html href

I'm newbie in web development and design, my question is the following:

When I'm creating my own page with following directory structure:

projectName [dir]
    |
    +-- public_html [dir]
            |
            +-- index.html  <-- main web page file
            +-- AnimationSrc [dir]
                    |
                    +-- animation1.html
                    +-- animation2.html
                    (...)

navigation from index.html to animation1.html is done using tag:

<li><a href="./AnimationsSrc/animation1.html" target="_self">Animation1</a></li>

Only this construction of href with leading dot and direct html file at end gives me correct results, which means that after selecting link I'm navigated from:

http://localhost:8383/ProjectName/index.html

To:

http://localhost:8383/ProjectName/AnimationsSrc/animation1.html

If I delete leading dot, instead I got:

http://localhost:8383/AnimationsSrc/animation1.html

Also, when I remove direct file name, page is not rendering as well.

But when I'm looking around other websites using firebug/any other browser tool I often see constructions like that:

From Bower.io:

<a href="/search">Search packages</a>

Where no leading dot is present and path is not pointing to specific html file

From Netbeans.org:

<a title="NetBeans&nbsp;IDE" href="/features/index.html">NetBeans IDE</a>

Where no leading dot is present.

Could someone please explain me, what's the difference? Why I'm forced to put that leading dot and direct link to html file, while e.g. Netbeas is doing same without leading dot, and bower only with directory? Is that related with underlying back-end technology? Some scripting?

Thank you in advance for help

2 个答案:

答案 0 :(得分:3)

/表示当前驱动器的根目录。

./表示当前目录。

../表示当前目录的父目录。

当你要移除时。然后使用/ in将导航到根目录,并将在根目录中搜索AnimationsSrc文件夹。

最佳做法是不使用/ ie。 HREF =&#34; AnimationsSrc / animation1.html&#34;

答案 1 :(得分:0)

区别在于

<a href="http://www.example.com/example.css">是一个绝对网址,它指向另一个网站。 <a href="/search">是相对网址,表示网站中的文件。

您可以在此处了解./和/差异:http://www.dirigodev.com/blog/seo-web-best-practices/relative-vs-absolute-urls-seo/