Blogger Information
Blog 14
fans 2
comment 1
visits 7885
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
flex弹性盒子:常用的六个元素
梦想
Original
544 people have browsed it

常用的六个元素

  1. 父级项目属性
  2. display:flex;声明当前盒子为弹性盒子
  3. 剩余空间分配方式
  4. place-content:start;剩余空间在右边
  5. place-content:end;剩余空间在左边显示
  6. place-content:center;剩余空间居中显示
  7. 剩余空间对齐方式
  8. place-content:space-between;剩余空间两边对齐
  9. place-content:space-around;剩余空间分散对齐
  10. place-content:space-enevly;剩余空间平均对齐
  11. 项目对齐方式
  12. place-items:stretch;自动伸展
  13. place-items:start;上对齐
  14. place-items:end;下对齐

实例:

  1. <div class="box">
  2. <div class="box1">flex1</div>
  3. <div class="box1">flex2</div>
  4. <div class="box1">flex3</div>
  5. </div>

默认块级,上下排序
声明弹性盒子(在父级声明)

  1. body .box{
  2. height: 20em;
  3. background-color: rgba(199, 196, 30, 0.603);
  4. border: 1px solid red;
  5. display: flex;
  6. }


设置子元素

  1. body .box .box1{
  2. width: 10em;
  3. border: 1px solid;
  4. }


剩余空间在右边place-content:start;默认值

剩余空间靠左显示place-content:end;

剩余空间居中分配place-content:center;

项目两边对齐中间自动分配place-content:space-between;

项目分散对齐place-content:around;

项目平均对齐place-content:evenly;项目之间的距离一样

项目在交叉轴上的对齐方式自动伸展place-items:stretch;

项目在交叉轴上上对齐place-items:start;

项目在交叉轴上下对齐place-items:end;

主轴方向flex-direction: column;切换交叉轴为主轴

是否换行显示flex-wrap:nowrap; wrap; nowrap不换显示(默认值)wrap 换行显示

主轴方向 换行显示简写flex-flow:row nowrap;第一个值主轴 第二个值是否换行

项目中的常用元素

设置项目是否缩小、放大、宽度flex:1 1 auto; 第一个值是否放大 1放大 0不放大 第二个值是否缩小 1缩小 0不缩小,第三个值设置宽度自动

设置项目响应式布局

  1. body .box .box1{
  2. width: 10em;
  3. border: 1px solid;
  4. /*不允许放大允许是缩小 宽度自动*/
  5. flex: 0 1 auto; /*默认值 可用 flex:auto; flex:1;表示*/
  6. /*允许放大 允许缩小 宽度自动*/
  7. flex: 1 1 auto;
  8. /*不允许放大 不允许缩小 宽度自动*/
  9. flex: 0 0 auto;/*flex: none表示*/
  10. }

设置项目的排列顺序

  1. body .box .box1:first-of-type{
  2. order:2;/*默认为0,数字越大排在前面 允许负数*/
  3. }


设置项目在交叉轴的对齐方式

向上排列

  1. body .box .box1:first-of-type{
  2. place-self:start;
  3. }


居中排列

  1. body .box .box1:first-of-type{
  2. place-self:center;
  3. }


向下排列

  1. body .box .box1:first-of-type{
  2. place-selfend;
  3. }

flex小案例

  1. <div class="header">
  2. <div class="logo">
  3. <img src="logo.png">
  4. </div>
  5. <div class="nav">
  6. <span><a href="">首页</a></span>
  7. <span><a href="">视频教程</a></span>
  8. <span><a href="">学习路径</a></span>
  9. <span><a href="">学习路径</a></span>
  10. <span><a href="">学习路径</a></span>
  11. <span><a href="">学习路径</a></span>
  12. <span><a href="">学习路径</a></span>
  13. <span><a href="">学习路径</a></span>
  14. <span><a href="">学习路径</a></span>
  15. </div>
  16. </div>
  17. <div class="bodyer">
  18. <div class="box">
  19. <ul>
  20. <li>php中文网</li>
  21. <li>php中文网</li>
  22. <li>php中文网</li>
  23. <li>php中文网</li>
  24. <li>php中文网</li>
  25. </ul>
  26. </div>
  27. <div class="box2">
  28. <img src="../小案例/img/12.jpg">
  29. </div>
  1. @import url(reset.css);
  2. body .header{
  3. margin-top: .625rem;
  4. height: 3em;
  5. background-color: white;
  6. display: flex;
  7. place-content: start;
  8. place-content: center;
  9. }
  10. body .logo{
  11. padding-top: 5px;
  12. }
  13. body .nav ul li{
  14. list-style-type: none;
  15. display: inline-block;
  16. }
  17. body .nav *{
  18. height: 3em;
  19. padding-left: 15px;
  20. place-content: end;
  21. }
  22. body .nav {
  23. place-content: center;
  24. }
  25. body .nav span > a{
  26. color: black;
  27. text-decoration: none;
  28. }
  29. body .bodyer{
  30. margin-top: 10px;
  31. height: 500px;
  32. /* border: 1px solid; */
  33. }
  34. body .bodyer{
  35. display: flex;
  36. place-content: center;
  37. /* background-color: white; */
  38. flex:1 1 auto;
  39. }
  40. body .bodyer div:first-of-type{
  41. width: 10%;
  42. height: 80%;
  43. /* border: 2px solid blue; */
  44. border-radius: 25px 0 0 0;
  45. background-color: white;
  46. }
  47. body .bodyer div:nth-of-type(2){
  48. width: 50%;
  49. height: 100%;
  50. /* border: 2px solid blue; */
  51. }
  52. body .bodyer div:last-of-type{
  53. width: 13%;
  54. height: 80%;
  55. border: 2px solid blue;
  56. }
  57. body .bodyer div:first-of-type ul li{
  58. list-style-type: none;
  59. line-height: 500%;
  60. }
  61. body .bodyer .box2 img{
  62. height: 80%;
  63. width: 100%;
  64. border-radius: 20px;
  65. }

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!