HTML |文件路径

文件路径指定文件在web文件夹结构中的位置。它就像一个文件的地址,帮助网络浏览器访问文件。文件路径用于链接外部资源,如图像、视频、样式表、JavaScript、显示其他网页等。 要在网页中插入文件,必须知道其来源。例如,语法( 图片[1]-HTML |文件路径-yiteyi-C++库 )用于插入图像文件,其中文件的路径在源(src)中提到。 文件路径有两种类型:

null
  • 绝对文件路径
  • 相对文件路径

绝对文件路径: 它描述了访问internet文件的完整地址(URL)。

图片[2]-HTML |文件路径-yiteyi-C++库

例子:

html

<!DOCTYPE html>
< html >
< head >
< title >Absolute file path</ title >
</ head >
< body >
alt = "My Image" style = "width:400px" >
</ body >
</ html >


输出:

图片[3]-HTML |文件路径-yiteyi-C++库

相对文件路径: 它描述了文件相对于当前网页文件位置的路径。 例1: 它显示当前网页文件所在文件夹中的文件路径。

html

<!DOCTYPE html>
< html >
< head >
< title >Relative file path</ title >
</ head >
< body >
< h2 >File present in the same folder</ h2 >
< img src = "images/geeks.jpg" alt = "My Image" style = "width:400px" >
</ body >
</ html >


输出:

relative file path

例2: 它显示当前网页文件文件夹上方文件夹中的文件路径。名为images的文件夹中的图像文件和当前网页文件存在于子文件夹中,则代码如下:

html

<!DOCTYPE html>
< html >
< head >
< title >Relative file path</ title >
</ head >
< body >
< h2 >File present in a folder above the current folder</ h2 >
< img src = "../images/geeks.jpg" alt = "My Image" style = "width:400px" >
</ body >
</ html >


输出:

relative file path

例3: 它显示当前子目录根目录下文件夹中的文件路径。

html

<!DOCTYPE html>
< html >
< head >
< title >Relative file path</ title >
</ head >
< body >
< h2 >File present in a folder which is located at< br >
the root of the current subdirectories</ h2 >
< img src = "/images/picture.jpg" alt = "My Image" style = "width:400px" >
</ body >
</ html >


输出:

relative file path

支持的浏览器:

  • 谷歌浏览器
  • 微软边缘
  • 火狐
  • 歌剧
  • 游猎

CSS是网页的基础,通过网站和Web应用程序来开发网页。您可以通过以下步骤从头开始学习CSS CSS教程 CSS示例 .

© 版权声明
THE END
喜欢就支持一下吧
点赞15 分享