我们应该在链接的绝对路径中使用前向斜线 /或Backslash \?

发布于 2025-01-23 05:22:33 字数 344 浏览 1 评论 0原文

所有这些绝对的链接路径都可以完美地工作。

<img src="\Users\dell\Desktop\brackets html files\Images\animal640.png" alt="">
<img src="/Users/dell/Desktop/brackets html files/Images/animal640.png" alt="">
<img src="\Users/dell\Desktop/brackets html files\Images\animal640.png" alt="">

但是我应该使用哪一个?推荐哪一个?它们有什么区别?

All of these absolute path of links are working perfectly.

<img src="\Users\dell\Desktop\brackets html files\Images\animal640.png" alt="">
<img src="/Users/dell/Desktop/brackets html files/Images/animal640.png" alt="">
<img src="\Users/dell\Desktop/brackets html files\Images\animal640.png" alt="">

But which one am I supposed to use? Which one is the recommended one? What is the difference between them?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

奢望 2025-01-30 05:22:33

URL使用前向斜杠(/)(在所有平台上)。

BackSlashes(\)用于Windows上的本地文件路径。 URL不是本地文件路径。甚至没有文件:方案URL是本地文件路径 - &nbsp;它们是URL。

URLs use forward slashes (/) (on all platforms).

Backslashes (\) are used for local file paths on Windows. URLs are not local file paths. Not even file: scheme URLs are local file paths — they are URLs.

甜扑 2025-01-30 05:22:33

我目前正在Angela Yu博士的Web Dev Bootcamp。她使用前向斜线用于本地文件(当然还有网站链接),但我选择将向后斜线用于本地文件和两个工作。我试图一丝不解地区分本地文件和URL,到目前为止,我还没有遇到任何问题。

编辑:我找到了另一个答案(

I am currently taking the Web Dev bootcamp of Dr. Angela Yu. She uses forward slashes for local files (and of course website links) but I instead opted to use backward slash for local files and both work. I'm trying to be meticulous as to differentiate local files and URLs and so far I have not encountered any problem yet.

Edit: I found another answer (https://www.htmlvalidator.com/CSS-HTML-Forum/viewtopic.php?t=2684#:~:text=Paths%20in%20HTML%20(like%20those,use%20the%20forward%20slash%20character.) saying that the browser converts a forward slash to a backslash should it need to access a local file. I guess it's better to follow Dr. Yu's formatting instead of eventually getting a problem in the future where I had to change all of the backslash into forward slashes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文