论坛风格切换切换到宽版
  • 3667阅读
  • 0回复

DIV+CSS中子div在父div居底 [复制链接]

上一主题 下一主题
离线网络天下
 

发帖
1528
铜币
22451
威望
510
只看楼主 倒序阅读 使用道具 楼主  发表于: 2012-07-18

简单的一个需求, 映射着常常被忽略的知识啊。
上次面试没写出来,得学习。

·思路及要点:

父div的位置设置成相对的,即“position: relative;”。
而子div的位置设置成绝对的,并且下边缘设为0,即“position: absolute; bottom: 0;”。

· 代码:
  1. <html>
  2. <head>
  3. <title>子div在父div中置底</title>
  4. <style type="text/css">
  5. .father { width: 500px; height: 600px; position: relative; background-color: AliceBlue; }
  6. .child { width: 400px; height: 100px; position: absolute; bottom: 0; background-color: AntiqueWhite; }
  7. </style>
  8. </head>
  9. <body>
  10. <div class="father">
  11. <div class="child">
  12. </div>
  13. </div>
  14. </body>
  15. </html>

快速回复
限100 字节
如果您在写长篇帖子又不马上发表,建议存为草稿
 
上一个 下一个