Flex, grid, media query to achieve responsive layout

Russian Xiaofa 2021-02-23 16:12:35
flex grid media query achieve


This article focuses on the use of Flex Layout 、Grid Layout and media query are three ways to realize responsive layout . The article deals with code online coding Address

design sketch :

 design sketch .png A word description : The screen size is different , The number of columns is different ,1-5 The number can be displayed according to the screen size 2 To 4 Column inequality ,6 The number one always dominates the line

Flex Layout

Ruan Yifeng Flex Layout explanation

programme 1( Each element is not magnified )

  1. Put form items that may appear on one line in a parent container
  2. Parent container settings flex-flow: row wrap; It means horizontal arrangement , Break lines when space is insufficient
  3. Set the... Of each element in the container flex: 0 0 420px;(420px For the base width of each element )
flex: 0 0 420px;
Equate to
flex-grow: 0;
flex-shrink: 0;
flex-basis: 420px;
 Copy code 

advantage :

  1. Without writing media query, the screen can be enlarged and the number of columns can be increased automatically
  2. When showing multiple lines , The rows and columns can be aligned up and down

shortcoming :

When the incremental space is insufficient , There are lots of blanks left on the right side , dissatisfaction UI Adaptation specifications Flex programme 1.png

programme 2( Each element magnifies )

  1. Put form items that may appear on one line in a parent container
  2. Parent container settings flex-flow: row wrap; It means horizontal arrangement , Break lines when space is insufficient
  3. Set the... Of each element in the container flex: 1 0 420px;
flex: 1 0 420px;
Equate to
flex-grow: 1;
flex-shrink: 0;
flex-basis: 420px;
 Copy code 

advantage :

  1. Without writing media query, the screen can be enlarged and the number of columns can be increased automatically
  2. There's not enough incremental space , Not enough to hold a new column , Other columns widen automatically

shortcoming :

  1. It shows that the column from the next row is not aligned with the corresponding column of the previous column ( Tried not to be realized through occupancy, etc , The number of fields is uncertain , It's not easy to occupy space )

Flex programme 2.png

Grid Layout

Ruan Yifeng Grid Layout explanation

  1. Set the parent container to grid Layout
  2. Set the width of each column to auto fill , Minimum width 420, Maximum 1fr
display: grid;
grid-template-columns: repeat(auto-fill, minmax(420px, 1fr));
 Copy code 

advantage

It can change with the screen size , The number of columns varies , It can be aligned up and down .

shortcoming

Compatibility issues Grid Compatibility .png Grid Layout .png If you don't think about compatibility , Consider using Grid Layout , Perfect implementation

media Media query

  1. Put form items that may appear on one line in a parent container
  2. Parent container settings flex-flow: row wrap; It means horizontal arrangement , Break lines when space is insufficient
  3. According to different screen width settings flex: 0 0 50%( Two )/33%( The three column )/25%( Four columns )
@media screen and (max-width: 1280px) {
flex: 0 0 50%;
}
@media screen and (min-width: 1281px) and (max-width: 1440px) {
flex: 0 0 33.33%;
}
@media screen and (min-width: 1441px) {
flex: 0 0 25%;
}
 Copy code 

advantage :

  1. Strong compatibility
  2. Realize the display of different number of columns under each screen size

shortcoming :

  1. Need to write multiple media queries

 Media query .png

Come here , Three ways to achieve responsive layout are recorded !! Make a little progress every day !

版权声明
本文为[Russian Xiaofa]所创,转载请带上原文链接,感谢
https://qdmana.com/2021/02/20210223155148660b.html

  1. RxHttp - 轻量级、可扩展、易使用、完美兼容MVVM、MVC架构的网络封装类库
  2. Rxhttp - lightweight, extensible, easy to use, perfectly compatible with MVVM, MVC architecture network encapsulation class library
  3. Rxhttp - lightweight, extensible, easy to use, perfectly compatible with MVVM, MVC architecture network encapsulation class library
  4. 前端面试常考题:JS垃圾回收机制
  5. Frequently asked questions in front end interview: JS garbage collection mechanism
  6. Rxhttp - lightweight, extensible, easy to use, perfectly compatible with MVVM, MVC architecture network encapsulation class library
  7. Java之HTTP网络编程(一):TCP/SSL网页下载
  8. HTTP network programming in Java (1): TCP / SSL web page download
  9. Java之HTTP网络编程(一):TCP/SSL网页下载
  10. HTTP network programming in Java (1): TCP / SSL web page download
  11. 使用vite搭建vue项目
  12. 在组件中展示pdf文件:vue-pdf (由于未找到方法滑动加载下一页,只能点击加载下一页pdf文件)
  13. 在 vue 中通过 express 连接数据库
  14. Using vite to build Vue project
  15. Display PDF file in component: Vue pdf
  16. Connecting database through express in Vue
  17. 2021届秋招哈啰出行前端面经(一面)
  18. vue使用sdk进行七牛云上传
  19. Javascript性能优化【内联缓存】 V8引擎特性
  20. Small true wireless smart headset evaluation: put intelligence into the ear
  21. The front end experience of the 2021 autumn recruitment
  22. Vue uses SDK to upload Qi Niu cloud
  23. 深入理解 Web 协议 (三):HTTP 2
  24. dhtmlxGantt如何重新排序任务
  25. JavaScript performance optimization [inline cache] V8 engine features
  26. 深入理解 Web 协议 (三):HTTP 2
  27. Deep understanding of Web protocol (3): http 2
  28. 深入理解 Web 协议 (三):HTTP 2
  29. How dhtmlxgantt reorders tasks
  30. 深入理解 Web 协议 (三):HTTP 2
  31. JavaScriptBOM操作
  32. JavaScriptBOM操作
  33. Deep understanding of Web protocol (3): http 2
  34. Deep understanding of Web protocol (3): http 2
  35. dhtmlxGantt甘特图重新排序任视频教程
  36. vue实现七牛云上传图片功能
  37. vue.js环境配置步骤及npm run dev报错解决方案
  38. Deep understanding of Web protocol (3): http 2
  39. JavaScript BOM operation
  40. JavaScript BOM operation
  41. Dhtmlxgantt reordering video tutorial
  42. Vue to achieve seven cattle cloud upload image function
  43. vue.js Environment configuration steps and NPM run dev error reporting solution
  44. 什么是HTTPS以及如何实施HTTPS?
  45. vue使用sdk进行七牛上传
  46. JavaScript 邮箱验证 - 正则验证
  47. Codeless development platform cloud watch sets off a "new revolution" in enterprise Digitalization
  48. Codeless development of cloud watch for enterprise digital solution
  49. What is HTTPS and how to implement it?
  50. Vue uses SDK to upload seven cows
  51. JavaScript mailbox verification - regular verification
  52. JavaScriptBOM操作
  53. JavaScript BOM operation
  54. How to create a new NPM package and publish it to the NPM community
  55. vue --tinymce 解决上传图片的方法
  56. Vue development
  57. A simple solution for vite to batch introduce SVG symbol
  58. Building 3D rendering engine from scratch with JS (2)
  59. Vue -- tinymece solution to upload pictures
  60. Common configuration of nginx