定位-相对定位
2018-09-18 06:32:42来源:博客园 阅读 ()
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>定位</title>
<style media="screen">
.box1{
width:100px;
height: 100px;
background-color: rgb(184, 208, 162);
}
.box2{
width:100px;
height: 100px;
background-color: rgb(231, 223, 143);
}
.box3{
width:100px;
height: 100px;
background-color: rgb(188, 211, 213);
}
</style>
</head>
<body>
<div class="box1">
</div>
<div class="box2"
</div>
<div class="box3">
</div>
</body>
</html>
输出:

定位:将指定的元素摆放到页面的任意位置
可以通过position属性来设置元素的定位
输入static:
.box2{
width:100px;
height: 100px;
background-color: rgb(231, 223, 143);
position: static;
}
输出:元素没有移动,static为默认值

relative:相对定位
.box2{
width:100px;
height: 100px;
background-color: rgb(231, 223, 143);
position: relative;
}
输出:当开启了元素的相对定位以后,而不设置偏移量时,元素不会发生任何变化

输入偏移量(left,right,top,bottom,一般选择水平方向的一个偏移量和垂直方向的一个偏移量进行定位就可以):
.box2{
width:100px;
height: 100px;
background-color: rgb(231, 223, 143);
position: relative;
left: 50px;
top: 100px;
}
输出:1、相对定位 relative 是相对于元素在文档流中原来的位置进行定位
2、相对定位会使元素上升一个层级
3、相对定位的元素不会脱离文档流

插入一个内联元素:
span{
background-color: rgb(209, 198, 209);
position: relative;
}
<span>span元素</span>
输出:相对定位不会改变元素的性质,块元素还是块元素,内联元素还是内联元素

标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:HTML
- 前端CSS五中元素定位类型 2020-06-01
- 5.通过定位实现二级菜单 2020-04-10
- 表单元素 2020-04-05
- HTML连载79-背景图片定位区域属性、背景颜色 2020-04-01
- position定位,CSS入门必备, 好像以后有个更厉害的flex! 2020-03-07
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash
