博客列表 >flex布局基础知识--php培训第九期线上班

flex布局基础知识--php培训第九期线上班

涤尘
涤尘原创
2019年11月06日 16:58:27621浏览

自学:align-self, order的用法

order:定义项目的排列顺序。数值越小,排列越靠前,默认为0
align-self该属性允许单个项目有与其它项目不一样的对齐方式, 可覆盖掉容器的flex-items属性 默认值: auto,表示继承父元素的align-items,如果没有父元素,则等价于stretch
  1. .demo1 > .item:first-of-type {
  2. order: 10;
  3. }
  4. .demo1 > .item:nth-last-of-type(3) {
  5. order: 8;
  6. }
  7. .demo1 > .item:nth-last-of-type(2) {
  8. order: 6;
  9. }
  10. .demo1 > .item:last-of-type {
  11. order: 1;
  12. align-self: flex-end;
  13. }

演示效果

用flex布局改圣杯布局

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>圣杯布局</title>
  6. <style type="text/css">
  7. header,footer {
  8. box-sizing: border-box;
  9. background-color: green;
  10. height: 50px;
  11. border: 1px solid;
  12. }
  13. main {
  14. display: flex;
  15. }
  16. main > aside {
  17. height: 600px;
  18. width: 200px;
  19. background-color: lightgreen;
  20. flex: none;
  21. }
  22. main > article{
  23. height: 600px;
  24. width: 100%;
  25. background-color: blue;
  26. flex: auto;
  27. }
  28. main > aside:first-of-type {
  29. order: -1;
  30. }
  31. </style>
  32. </head>
  33. <body >
  34. <header>头部</header>
  35. <main>
  36. <article>主体内容区</article>
  37. <aside >左侧</aside>
  38. <aside >右侧</aside>
  39. </main>
  40. <footer>底部</footer>
  41. </body>
  42. </html>

效果图

总结:需要多写多练,关于flex要灵活运用。

手抄代码如下:











声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议