我们应该在链接的绝对路径中使用前向斜线 /或Backslash \?
所有这些绝对的链接路径都可以完美地工作。
<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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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 evenfile:
scheme URLs are local file paths — they are URLs.我目前正在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.