17_定位
时间:2022-08-05
本文章向大家介绍17_定位,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
默认情况
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> div{ margin: 10px; padding: 5px; font-size: 12px; line-height: 25px; } #father{ border: 1px solid #536; padding: 0; } #first{ background: brown; border: 1px dashed #0852e7; } #second{ background: #8c6666; border: 1px dashed #1ae7df; } #third{ background: #727085; border: 1px dashed #f12c07; } </style> </head> <body> <div id="father"> <div id="first">第一个盒子</div> <div id="second">第二个盒子</div> <div id="third">第三个盒子</div> </div> </body> </html>
结果展示
相对定位
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <!--相对定位 相对于自己原来的位置进行偏移--> <style> body{ padding: 20px; } div{ margin: 10px; padding: 5px; font-size: 12px; line-height: 25px; } #father{ border: 1px solid #536; padding: 0; } #first{ background: brown; border: 1px dashed #0852e7; position: relative;/*相对定位:上下左右*/ top:-20px; left: +20px; } #second{ background: #8c6666; border: 1px dashed #1ae7df; } #third{ background: #727085; border: 1px dashed #f12c07; position: relative; bottom: -10px; right: 20px; } </style> </head> <body> <div id="father"> <div id="first">第一个盒子</div> <div id="second">第二个盒子</div> <div id="third">第三个盒子</div> </div> </body> </html>
结果展示
练习
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> #box{ width: 300px; height: 300px; padding: 10px; border: 3px solid red; } a{ background: pink; width: 100px; height: 100px; line-height: 100px; text-align: center; color: white; display: block; text-decoration: none; } a:hover{ background: blue; } .a2,.a4{ position: relative; right: -200px; top: -100px; } .a5{ position: relative; right: -100px; top: -300px; } </style> </head> <body> <div> <div id="box"> <a class="a1" href="#">链接1</a> <a class="a2" href="#">链接2</a> <a class="a3" href="#">链接3</a> <a class="a4" href="#">链接4</a> <a class="a5" href="#">链接5</a> </div> </div> </body> </html>
结果展示
绝对定位
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>绝对定位</title> <!-- 1、没有父级定位的前提下,相对于浏览器定位 2、假设父级元素存在定位,我们通常会相对于父级元素进行偏移 --> <style> div{ margin: 10px; padding: 5px; font-size: 12px; line-height: 25px; } #father{ border: 1px solid #536; padding: 0; position: relative; } #first{ background: brown; border: 1px dashed #0852e7; } #second{ background: #8c6666; border: 1px dashed #1ae7df; position: absolute; left: -10px; } #third{ background: #727085; border: 1px dashed #f12c07; position: relative; } </style> </head> <body> <div id="father"> <div id="first">第一个盒子</div> <div id="second">第二个盒子</div> <div id="third">第三个盒子</div> </div> </body> </html>
结果展示
固定定位
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> body{ height: 1000px; } div:nth-of-type(1){/*绝对定位:相当于浏览器*/ width: 100px; height: 100px; background: red; position: absolute; right: 0; bottom: 0; } div:nth-of-type(2){/*fixed,固定定位*/ width: 50px; height: 50px; background: yellow; position: fixed; right: 0; bottom: 0; } </style> </head> <body> <div>div1</div> <div>div2</div> </body> </html>
结果展示
zindex代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <link rel="stylesheet" href="css/style.css"> </head> <body> <div id="content"> <ul> <li><img src="images/bj.jpg" alt=""></li> <li class="tipText">学习微服务,找我</li> <li class="tipBg" ></li> <li>时间:2099-01-01</li> <li>地点:月球一号基地</li> </ul> </div> </body> </html>
style代码
#content{ width: 330px; padding: 0px; margin: 0px; overflow: hidden; font-size: 12px; line-height: 25px; border: 1px black solid; } ul,li{ padding: 0px; margin: 0px; list-style: none;/*去除圆点*/ } #content ul{ position: relative; } .tipText,.tipBg{ position: absolute; width: 330px; height: 25px; top: 200px; } .tipText{ color: white; z-index: 0; } .tipBg{ background: black; opacity: 0.5;/*背景透明度*/ }
结果展示
原文地址:https://www.cnblogs.com/tuyin/p/16555586.html
- async和enterproxy控制并发数量
- 从零开始写项目终极【维护网站、修复Bug】
- Redis 数据结构与内存管理策略(下)
- Redis 数据结构与内存管理策略(上)
- Servlet第三篇【request和response简介、response的常见应用】
- Java 10的10个新特性,将彻底改变你写代码的方式!
- JDK9新特性实战:简化流关闭新姿势。
- Druid数据库连接池就是这么简单
- 使用 github 做代码管理,知道这些就够了
- 二叉树就这么简单
- Elasticsearch就是这么简单
- 让 MyBatis Generator 变的更简单
- SpringMVC【参数绑定、数据回显、文件上传】
- SDNLAB技术分享(五):浅谈Open vSwitch移植
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Flutter路由跳转及参数传递
- 动手实现扩展属性为对象动态添加获取数据(续)
- [Flutter]使用主题
- 让Silverlight AutoCompleteBox控件支持多属性筛选
- 使用Rx Framework实现XAML中的物体拖动
- Flutter中ScrollView及其子类(ListView等)的下拉刷新
- MVVM绑定多层级数据到TreeView并设置项目展开
- 【iOS 开发】WebViewJavaScriptBridge 实现原理
- 最新Linux部署.NET,Mono and DNX
- Flutter TextStyle参数解析关于学习
- [Flutter]使用顶部切换导航TabBar
- [Flutter]使用SnackBar
- 在VS中使用TinyFox调试OWIN应用(转)
- [Flutter]md5加密
- [Flutter]请求阿里百川的API