HTML <img>使用说明-相对路径与绝对路径

本文介绍了网页设计中图片路径的两种类型:相对路径与绝对路径。详细解释了它们的区别及如何在HTML中正确使用这两种路径。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.相对路径

外网相对路径:

<img src="/i/eg_tulip.jpg" alt="小妞妞" />

本地相对路径(两个同级的文件)可以直接访问如:

<img src="eg_tulip.jpg" alt="小妞妞" />

2.绝对路径

外网绝对路径:

<img src="http://boonyaxnn.blog.163.com/http://www.w3school.com.cn/i/eg_tulip.jpg" alt="小妞妞" />

本地磁盘绝对路径需要加“file:///"前缀,如:file:///C:/Users/Administrator/Desktop/html/index.html

img使用说明-相对路径与绝对路径 - boonyaxnn - boonyaxnn的博客
 点击页面右键,查看源代码:本地绝对路径-file:///D:/Favorites/eg_tulip.jpg
img使用说明-相对路径与绝对路径 - boonyaxnn - boonyaxnn的博客
 
``` <template> <lay-layout class="home-class"> <lay-header> <lay-logo class="logo">工单管理系统</lay-logo> <lay-switch v-model="collapse"></lay-switch> <lay-switch v-model="active20"></lay-switch> <lay-dropdown> <lay-button type="text" icon="layui-icon-user"></lay-button> <template #content> <lay-dropdown-menu> <lay-dropdown-menu-item>个人中心</lay-dropdown-menu-item> <lay-dropdown-menu-item divided>退出登录</lay-dropdown-menu-item> </lay-dropdown-menu> </template> </lay-dropdown> </lay-header> <lay-layout class="flex-container"> <!-- 侧边菜单 --> <lay-side> <lay-menu :collapse="collapse" :tree="isTree" :theme="active20 ? 'dark' : 'light'" :selected-key="selectedKey" :open-keys="openKey" @changeSelectedKey="changeSelectedKey"> <lay-menu-item id="/"> <template #icon> <lay-icon type="layui-icon-home"></lay-icon> </template> <template #title> 首页 </template> </lay-menu-item> <lay-sub-menu id="/processUsage"> <template #icon> <lay-icon type="layui-icon-template"></lay-icon> </template> <template #title> 流程使用 </template> <lay-menu-item id="/apply">工单申请</lay-menu-item> <lay-menu-item id="/draft">草稿箱</lay-menu-item> <lay-menu-item id="/todo">待办事项</lay-menu-item> </lay-sub-menu> <lay-sub-menu title="流程查询" is="queryProcess"> <template #icon> <lay-icon type="layui-icon-search"></lay-icon> </template> <template #title> 流程查询 </template> <lay-menu-item id="/query">工单查询</lay-menu-item> <lay-menu-item id="/my-process">我的发起</lay-menu-item> <lay-menu-item id="/processed">已处理工单</lay-menu-item> </lay-sub-menu> <lay-sub-menu title="系统管理" v-if="isAdmin" id="/system"> <template #icon> <lay-icon type="layui-icon-set"></lay-icon> </template> <template #title> 系统管理 </template> <lay-menu-item id="/permission">权限管理</lay-menu-item> <lay-menu-item id="/workflow">流程配置</lay-menu-item> </lay-sub-menu> </lay-menu> </lay-side> <!-- 主体内容 --> <lay-body style="padding: 20px"> <!-- 面包屑 --> <GlobalBreadcrumb></GlobalBreadcrumb> <router-view /> </lay-body> </lay-layout> </lay-layout> </template> <script setup> import { ref } from 'vue'; import GlobalBreadcrumb from '../components/global/GlobalBreadcrumb.vue'; const isAdmin = ref(true); const collapse = ref(false); const active20 = ref(false); const selectedKey = ref("/") const openKey = ref(["/"]) const isTree = ref(true) </script>```lay-logo 加背景图
03-12
<template> <div class="common-layout"> <el-container> <el-header> <div class="h-left"> <img class="logo" src="../src/assets/logo.png" alt=""> <div class="h-left-text"> <p class="p1">保尔旅行管理系统</p> <p class="p2">BAOER</p> </div> </div> <div class="h-right"> <img class="user" src="../src/assets/user.png" alt=""> <p class="user-name">管理员</p> <p class="logout">退出</p> </div> </el-header> <el-container> <el-aside style="background-color:#31303D"> <el-col> <el-menu router background-color="#31303D" text-color="#fff" active-text-color="#ffd04b" default-active="2" class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose"> <el-menu-item index="table"> <img src="../src/assets/图标-首页.png" alt=""> <span>首页</span> </el-menu-item> <el-menu-item index="order"> <img src="../src/assets/图标-订单管理.png" alt=""> <span>订单管理</span> </el-menu-item> <el-sub-menu index="userManagement"> <template #title> <img src="../src/assets/图标-用户管理.png" alt=""> <span>用户管理</span> </template> <el-menu-item index="branchMsg">分店信息</el-menu-item> <el-menu-item index="branchSales">分店销售</el-menu-item> <el-menu-item index="headOfficeOperator">总店操作员</el-menu-item> </el-sub-menu> <el-menu-item index="branchManagement"> <img src="../src/assets/图标-分店管理.png" alt=""> <span>分店管理</span> </el-menu-item> <el-sub-menu index="tripMsg"> <template #title> <img src="../src/assets/图标-旅行信息.png" alt=""> <span>旅行信息</span> </template> <el-menu-item index="branchMsg">旅行类型</el-menu-item> </el-sub-menu> <el-sub-menu index="sales"> <template #title> <img src="../src/assets/图标-销售统计.png" alt=""> <span>销售统计</span> </template> <el-menu-item index="salesRecords">销售记录</el-menu-item> </el-sub-menu> </el-menu> </el-col> </el-aside> <el-main> <router-view></router-view> </el-main> </el-container> </el-container> </div> </template> <script setup lang='ts'> import router from '../src/router' // import {ref,reactive} from 'vue' const handleOpen = (key: string, keyPath: string[]) => { console.log(key, keyPath) } const handleClose = (key: string, keyPath: string[]) => { console.log(key, keyPath) } // const handleUM = () => { // router.push('/userManagement') // } // const handleTS = () => { // router.push('/tripMsg') // } // const handleSales = () => { // router.push('/sales') // } </script> <style scoped lang='less'> * { margin: 0; padding: 0; box-sizing: border-box; } html, body { width: 100%; height: 100%; overflow: hidden; } .common-layout { width: 100vw; height: 100vh; display: flex; flex-direction: column; } header { background-color: #31303D; display: flex; width: 100vw; height: 10vh; min-height: 80px; justify-content: space-between; .h-left { display: flex; width: 30%; align-items: center; .logo { height: 70%; margin-left: 2%; } .h-left-text { display: flex; flex-direction: column; justify-content: center; align-items: center; color: white; font-size: 20px; margin-left: 2%; .p1 { font-weight: 700; } .p2 { font-size: 12px; font-weight: 400; } } } .h-right { display: flex; margin-right: 1%; width: 10%; justify-content: center; align-items: center; .user { height: 50%; } .user-name, .logout { color: white; font-size: 20px; margin-left: 2%; } .logout { cursor: pointer; margin-left: 10%; &:hover { color: red; } } } } .el-container { display: flex; flex: 1; min-height: 0; .el-aside { width: 15vw; min-width: 200px; height: 100%; overflow-y: auto; } .el-main { flex: 1; padding: 15px; height: 100%; overflow-y: auto; width: 85vw; } } </style>点击侧边栏的一级菜单(非子菜单)和二级菜单都能进行路由跳转,并且互不影响。如何实现
最新发布
07-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值