博主信息
博文 34
粉丝 0
评论 0
访问量 26314
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
flex初体验之常用属性练习
小庄
原创
561人浏览过

flex初体验之常用属性练习

实例演示flex容器与项目中常用的属性,并写出功能

  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>Document</title>
  8. </head>
  9. <style>
  10. * {
  11. margin: 0px;
  12. padding: 1px;
  13. box-sizing: border-box;
  14. }
  15. .container{
  16. display: flex;
  17. height: 20rem;
  18. /* 居中 */
  19. justify-content: center;
  20. /* 从做往右 */
  21. justify-content: flex-start;
  22. /* 从右往左 */
  23. justify-content: flex-end;
  24. /* 若设置对齐方式 以上左右居中将无效 */
  25. /* 二端对齐 */
  26. justify-content: space-between;
  27. /* 分散对齐 相邻两个会有左右相加的距离 */
  28. justify-content: space-around;
  29. /* 平均对齐 */
  30. justify-content: space-evenly;
  31. background-color: lawngreen;
  32. }
  33. .container > .item {
  34. width: 5rem;
  35. height: 15rem;
  36. align-content: center;
  37. background-color: lightcoral;
  38. }
  39. .container1 {
  40. display: flex;
  41. background-color: lightpink;
  42. height: 15rem;
  43. flex-direction: column;
  44. }
  45. .container1 > .item {
  46. display: flex;
  47. height: 15rem;
  48. justify-content: center;
  49. background-color:lightslategray;
  50. }
  51. .container1 > .item:first-of-type{
  52. background-color:magenta;
  53. }
  54. .container1 > .item:last-of-type{
  55. background-color: lightcoral;
  56. }
  57. </style>
  58. <body>
  59. <!-- flex 只影响当前子元素,不仅不会影响子元素内的子元素,且flex可以嵌套 -->
  60. <div class="container">
  61. <div class="item">1</div>
  62. <div class="item">2</div>
  63. <div class="item">3</div>
  64. </div>
  65. <div class="container1">
  66. <div class="item">1</div>
  67. <div class="item">2</div>
  68. <div class="item">3</div>
  69. </div>
  70. </body>
  71. </html>
批改老师:PHPzPHPz

批改状态:合格

老师批语:
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系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+教程免费学