博主信息
博文 31
粉丝 2
评论 0
访问量 35211
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
CSS盒子模型
霏梦
原创
841人浏览过
  • 作者:霏梦

    盒子模型

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>盒/框模型</title>
  7. <style>
  8. .box {
  9. /* 宽高叫内容区 */
  10. width: 200px;
  11. height: 200px;
  12. }
  13. .box.one {
  14. /* 上右下左,顺时针方向 */
  15. padding: 10px;
  16. /* 浏览器计算有规则,有误差,这是正常的,你看到的是 */
  17. border: 2px solid red;
  18. background-color: lightgreen;
  19. /* 内容裁切 只到内容区,就能看到padding*/
  20. background-clip: content-box;
  21. /* margin:top right bottom left; */
  22. /* margin: 0 0 20px 0; */
  23. margin-bottom: 20px;
  24. }
  25. .box.two {
  26. padding: 10px;
  27. border: 2px solid red;
  28. background-color: coral;
  29. background-clip: content-box;
  30. /* 当二个盒子在垂直方向,外边距产生折叠 */
  31. margin-top: 30px;
  32. }
  33. .box.dad {
  34. background-color: lightseagreen;
  35. /* 一旦一个元素被添加了position,且值不是static(默认值),那么它就是定位元素 */
  36. position: relative;
  37. /* 从浏览器左边过来50,也可以从上面过来; */
  38. /* 相对定位,相对自己做了偏移,也就是这个元素在文档中的位置不释放 */
  39. /* left: 50px; */
  40. /* top: 50px; */
  41. }
  42. .son {
  43. width: 100px;
  44. height: 100px;
  45. background-color: magenta;
  46. /* 绝对定位 相对于它的定位父级进行定位 */
  47. /* 做下面的定位时,把dad里面的定位值注释掉,然后再打开,作对比 */
  48. /* 最大的父级是body */
  49. position: absolute;
  50. /* 固定位位 他是忽略你的定位父级,总是以body进行定位,如广告*/
  51. position: fixed;
  52. left: 50px;
  53. top: 50px;
  54. }
  55. </style>
  56. </head>
  57. <body>
  58. <!-- 块元素独占一行,默认垂直排列 -->
  59. <div class="box one"></div>
  60. <div class="box two"></div>
  61. <div class="box dad">
  62. <div class="box son"></div>
  63. </div>
  64. </body>
  65. </html>
批改老师:WJWJ

批改状态:合格

老师批语:总结过于简单,建议修改下标题,填充点内容,附上图片!
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学