1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>定位与定位元素</title>
  8. </head>
  9. <body>
  10. <!-- 文档流:显示顺序和书写顺序一致 -->
  11. <!-- 文档流默认position:static -->
  12. <div class="box parent">
  13. <div class="box child first"></div>
  14. <div class="box child"></div>
  15. </div>
  16. </body>
  17. </html>
  18. <style>
  19. body{
  20. border: 1px solid #000;
  21. }
  22. .box {
  23. border: 1px solid #000;
  24. }
  25. .box.parent{
  26. width: 300px;
  27. height: 400px;
  28. background-color: lightcyan;
  29. }
  30. .box.child{
  31. width:150px;
  32. height: 150px;
  33. background-color: yellow;
  34. }
  35. .box.child.first{
  36. width:150px;
  37. height: 150px;
  38. background-color: lightgreen;
  39. /* 1 相对定位 */
  40. position:relative;
  41. /* 相对于自身在文档流中的位置,元素仍然在文档流中国,原占空间不释放,
  42. 只有相对原位置进行了偏移 */
  43. top:30px;
  44. left:30px;
  45. /* 2 绝对定位 */
  46. /* 相对于他的包含快,看他的元素结构了
  47. 能充当绝对定位包含快的元素,必须是定位元素
  48. 不能是static就可以了
  49. 如果绝对定位元素向上一直找不到可定位的父级,那就相对于Body/html*/
  50. position:absolute;
  51. }
  52. .box.parent{
  53. /* 设定定位参考父级,包含快 */
  54. position: relative;
  55. }
  56. /* 相对定位:相对自身,在文档流中
  57. 绝对定位:相对包含快,不在文档流中 */
  58. /* 3 固定定位 */
  59. /* 永远不动了,是绝对定位的一个子集,就是绝对定位
  60. ,只是包含快是固定,永远是Body/html
  61. */
  62. .box.child.first{
  63. position: fixed;
  64. }
  65. </style>

更多相关文章

  1. android shape 使用小结
  2. Android判断定位功能是否开启
  3. Delphi XE7 GPS控件android下的新变化
  4. Android布局文件属性
  5. android 界面布局 很好的一篇总结 【转】
  6. 让editView、AutoCompleteTextView开始捕获的焦点
  7. Android(安卓)JNI编程内存问题定位方法
  8. android 界面布局 很好的一篇总结 【转】
  9. android 基于百度地图api获取经纬度

随机推荐

  1. 外部主机不允许连接Mysql设置的解决方法
  2. MySQL JOIN 多表连接
  3. Mac本如何卸载MySQL
  4. Oracle 尽量避免在SQL语句中使用 OR
  5. [SQL SERVER系列]工作经常使用的SQL整理,
  6. MSSQL中类似MySQL的limit参数
  7. 如何找到一个具有负值而另一个具有相同正
  8. 求助,关于sql带入参数的写法问题。
  9. 参数化的Insert语句,事务抛出错误
  10. linux 上安装postgresql 并配置pgadmin i