position:fixed/absolute和float的关系:
元素设置position:absolute / fixed后,float属性是没有效果的。
对于position: absolute元素,其包含元素为设有position:relative的元素;
对于position: fixed元素,其包含元素为HTML,而HTML视为窗口大小,如果html的范围大于body,可设置html最大宽度值,并body设置transform: translateX(0)属性,则fixed元素可位于body内。
对于position: relative元素,其包含块同absolute一样,但对float不为none值情况下,会先进行浮动再设置position的left或right。

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1"/>
<title>Title</title>
<style>
html {
position: relative;
height: 100%;
max-width: 540px;
margin: 0 auto;
background: #eee;
}
body {
width: 100%;height: 100%;
margin: 0 auto;
background: #fff;
transform: translateX(0);
}
.parentBox {
position: relative;
width: 300px;height: 150px;
border: 1px dotted #000;
}
.childBox {
position: fixed;
float: left;
top: 0;
right: 0;
width: 100px;
height: 100px;
border: 1px solid #fc0;
} .childBox2 {
position: absolute;
float: left;
} .childBox3 {
position: relative;
right: 50px;
float: left;
}
</style>
</head>
<body>
<div class="parentBox">
<span>relative</span>
<div class="childBox">fixed</div>
<div class="childBox childBox2">absolute</div>
<div class="childBox childBox3">relative<br/>right:50px<br/>float:left</div>
</div>
</body>
</html>

 

最新文章

  1. MyBatis入门基础(一)
  2. 使用powershell链接到Azure
  3. 快速入门系列--MVC--04模型
  4. Xperf Basics: Recording a Trace (the easy way)(转)
  5. fullpage.js 结合固定导航栏—实现定位导航栏
  6. UIAlertView[警告框] [代理协议型]UIActionSheet [表单视图][代理协议型]
  7. 一.Nginx的特性和一些知识点
  8. Triangle - POJ 2954(求三角形内的格子点的个数)
  9. IOS中的id与nil
  10. Java没有源代码的同步集合~
  11. Java基础之路(三)下--流程控制语句
  12. java 集合类Array、List、Map区别和优缺点
  13. tomcat之过滤器
  14. &lt;%@include&gt;和&lt;jsp:include&gt;有什么不同呢
  15. laravel 数据库获取值的常用方法
  16. 201621123001 《java程序设计》 第3周学习总结
  17. Java第12章笔记
  18. selenium WebDriver处理文件下载
  19. 凸包算法(Graham扫描法)详解
  20. sqlserver卸载

热门文章

  1. 记一些css 3效果
  2. React中Ref 的使用 React-踩坑记_05
  3. notification(浏览器通知)
  4. spring security简介与使用
  5. CCF201909-1小明种苹果
  6. Java JDK 动态代理实现和代码分析
  7. css使Img图片居中显示
  8. 项目中常用到的布局 flex
  9. Java报错:Failed to execute goal org.eclipse.jetty:jetty-maven-plugin:9.4.26.v20200117:run (default-cli) on project ssm-mybatis-plus: Failure
  10. Python入门-变量与命名