1

1

1

CSS 定位 relative && absolute 问题?

谁能解释一下,为什么div使用 relative是设置right,bottom 后,看不到div 呀,哪里多出来的 top , left 属性负值呀?

(已测试了所有最新的浏览器,自动添加的top , left 属性负值)

demo:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>CSS 定位:relative && absolute</title>
<style>
*{
margin: 0;
padding: 0;
}
html,body{
width: 100%;
height: 100%;
background: rgba(0,0,0,0.3);
color: red;
box-sizing: border-box;
overflow: hidden;
}
.relative{
background-color: #f0f;
width: 100px;
height: 100px;
position: relative;
right: 100px;
bottom: 100px;
/*
position: relative; 浏览器,自动补全 :
left == -right;
top == -bottom;
*/
}
</style>
</head>
<body>
<div class="box">
<div class="relative">
<!--comments-->
</div>
</div>
</body>
</html>

1.

2. chrome 中修改后,

3. 同样,设置 left,top 后, 多出来 right/bottom 的负值属性?

1

demo:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>CSS 定位:relative && absolute</title>
<style>
*{
margin: 0;
padding: 0;
}
html,body{
width: 100%;
height: 100%;
background: rgba(0,0,0,0.3);
color: red;
box-sizing: border-box;
overflow: hidden;
}
.box{
width: 1000px;
height: 600px;
border: 1px solid red;
/*overflow: hidden;*/
}
.box .relative{
background-color: #f0f;
width: 100px;
height: 100px;
position: relative;
right: 50px;
bottom: 50px;
/*
position: relative; 浏览器,自动补全 :
left == -right;
top == -bottom;
*/
}
.box .relative-new{
background-color: #0f0;
width: 100px;
height: 100px;
position: relative;
right: 0;
bottom: 0;
}
</style>
</head>
<body>
<div class="box">
<div class="relative">
<h3>relative</h3>
</div>
<div class="relative-new">
<h3>relative-new</h3>
</div>
</div>
</body>
</html>

1

demo:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>CSS 定位:relative && absolute</title>
<style>
*{
margin: 0;
padding: 0;
}
html,body{
width: 100%;
height: 100%;
background: rgba(0,0,0,0.3);
color: red;
box-sizing: border-box;
overflow: hidden;
}
.box{
width: 1000px;
height: 600px;
border: 1px solid red;
/*overflow: hidden;*/
}
.box .relative{
background-color: #0f0;
width: 100px;
height: 100px;
position: relative;
right: 100px;
bottom: 100px;
/*
*/
}
.box .relative-new{
background-color: #0f0;
width: 100px;
height: 100px;
position: relative;
left: 100px;
top: 100px;
}
.box .absolute{
background-color: #0f0;
width: 100px;
height: 100px;
position: absolute;
right: 100px;
bottom: 100px;
/*
position:absolute;
right: 200px;
bottom: 200px;
这样才好使!
//position:absolute; float脱离文档流
*/
}
</style>
</head>
<body>
<div class="box">
<div class="relative">
<h3>relative</h3>
</div>
<div class="relative-new">
<h3>relative-new</h3>
</div>
<div class="absolute">
<h3>absolute</h3>
</div>
</div>
</body>
</html>

1

1

1

1

1

1

1

1

1

1

1

1

最新文章

  1. Hibernate5.2之反向工程
  2. How to set colors of HTML tables
  3. Luncene 学习入门
  4. How to setup ELM327 Bluetooth WiFi for Android software Torque
  5. Asp.net MVC 自定义路由在IIS7以上,提示Page Not Found 解决方法
  6. jQuery之对话框
  7. python 数据类型(元组(不可变列表),字符串
  8. Python 跳出多重循环
  9. python基础教程(八)
  10. kali git 环境配置
  11. appium 元素定位find_element_by_android_uiautomator方法使用
  12. centos7中设置nginx的systemctl启动方式
  13. 关于Failed to check the status of the service com.taotao.service.ItemService. No provider available fo
  14. Effective Java 第三版—— 87. 考虑使用自定义序列化形式
  15. centos docker compose安装
  16. 1012 The Best Rank (25 分)
  17. Spring笔记②--各种属性注入
  18. 打包python脚本为exe的坎坷经历, by pyinstaller方法
  19. C#串口serialPort操作
  20. Codeforces Beta Round #8 C. Looking for Order 状压

热门文章

  1. Service Mesh 在百度网盘数万后端的落地实践
  2. 如何设计一个亿级网关(API Gateway)?
  3. python基础(数据类型,while,if)
  4. Spring Cloud Config、Apollo、Nacos配置中心选型及对比
  5. MySql(五)SQL优化-优化SQL语句的一般步骤
  6. Zabbix系列优秀博文
  7. Mysql数据库版本高低引起的group by问题
  8. hbase笔记---新版api之对表的操作,指定region创建,普通创建,删除,修改列族信息
  9. 华三交换机NTP配置
  10. 关于base64编码Encode和Decode编码的几种方式--Java